codeforces Educational Codeforces Round 21 C. Tea Party

本文介绍了一种茶水分配算法:先将杯子按容量排序并倒入一半茶水,不足则返回-1;剩余茶水继续填充至最大容量。使用结构体记录杯子编号确保顺序。

先把所有的杯子按尺寸大小排序,然后把每个杯子都倒上一半,若是不够就输出-1,若是没倒完就从尺寸大的开始都倒满,一直到把所有茶都倒完,因为排序的时候后打乱顺序,所以用结构体来记录杯子序号即可。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<ctime>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<set>
#include<bitset>
#include<map>
#include<tr1/unordered_map>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#define INF 0x3f3f3f3f
#define inf 2*0x3f3f3f3f
#define llinf 1000000000000000000
#define pi acos(-1.0)
#define mod 1000000007
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lrt rt<<1
#define rrt rt<<1|1
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define per(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define mem(a,b) memset(a,b,sizeof(a))
#define lb(x) (x&-x)
#define gi(x) scanf("%d",&x)
#define gi2(x,y) scanf("%d%d",&x,&y)
#define gll(x) scanf("%lld",&x)
#define gll2(x,y) scanf("%lld%lld",&x,&y)
#define gc(x) scanf("%c",&x)
#define gc2(x,y) scanf("%c%c",&x,&y)
using namespace std;
using namespace std::tr1;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int>P;
/***********************************************/
int n,w,sum=0,ss[105];
struct node
{
    int v,num,s;
}a[105];
bool cmp(node a,node b)
{
    return a.v<b.v;
}
int main()
{
    cin>>n>>w;
    rep(i,0,n)
    {
        gi(a[i].v);
        a[i].num=i;
        sum+=(a[i].v+1)/2;
    }
    if(sum>w)return cout<<-1,0;
    sort(a,a+n,cmp);
    rep(i,0,n)
    {
        a[i].s=(a[i].v+1)/2;
        w-=(a[i].v+1)/2;
    }
    int x=n-1;
    while(w>0)
    {
        int xx=a[x].v-a[x].s;
        a[x].s+=min(xx,w);
        w-=xx;
        x--;
    }
    rep(i,0,n)
    {
        ss[a[i].num]=a[i].s;
    }
    rep(i,0,n)cout<<ss[i]<<' ';
    return 0;
}


### 关于Educational Codeforces Round 175 对于Div. 2参赛者的信息 针对编号为175的教育轮次比赛,在Codeforces平台上的此类赛事通常面向不同级别的编程爱好者开放,但有着特定的规定来区分参与者的分组。对于Div. 2的参与者而言,此级别通常是为那些评级低于2100的程序员准备的比赛环境[^1]。 值得注意的是,虽然提及到trusted participants的概念主要适用于第三级别的正式排名表单中的成员资格定义,即仅限参加了至少两个评分赛(每次比赛中解决了一个以上的问题),并且未曾达到过1900或更高的分数的选手才能成为受信任的第三级别成员;然而这一规定并不直接影响Div. 2参赛者的分类标准。 为了获取关于Educational Codeforces Round 175更具体的数据,比如确切的时间安排、题目列表以及特殊规则等细节,建议访问官方公告页面查看由主办方发布的最新消息和指南。这些资源能够提供最权威的第一手资料给有兴趣参加该活动的人士。 ```python # Python代码示例用于展示如何通过API查询比赛信息(假设存在这样的功能) import requests def get_contest_info(contest_id): url = f"https://codeforces.com/api/contest.standings?contestId={contest_id}" response = requests.get(url).json() if 'result' in response: contest_data = response['result']['contests'][0] return { "name": contest_data["name"], "startTimeSeconds": contest_data["startTimeSeconds"], "durationSeconds": contest_data["durationSeconds"] } else: return None print(get_contest_info(175)) ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值