Codeforces Round #428 (Div. 2) 839B. Game of the Rows(思维+贪心)

41 篇文章 0 订阅

写于newbee被李逵三比零之后.
关了直播,改了一个地方,就a了,可能我不要想太多无关的东西把.
这题讲实话我觉得挺难做的,如果不是在cf上可以看到数据,可能还要很久我才能a.
我的思路是把每一个军团的人,都分成三种,4个人一组,两个人一组,一个人一组,这样的话呢,两个人和一个人的组,每个军团最多一个.(关键)
然后就是贪心的策略,飞机中间的座位,一定要给四人连坐,因为这样不会浪费位置.然后如果四人座坐不完四人组,四人组就拆开,去坐两边.
然后处理二人组,同理,二人组要优先坐两边的位置.
然后一人,如果两边还有剩余,就让他们坐过去.
最后,我们的中间四人座,只坐了四人组对吧?因为这个地方,一排最多可以坐三个人,所以要特殊考虑,余下的二人组,最多占满同一侧,其他就可以给一个人了,但是注意到,二人组也可以拆开,所以就又要加一层判断.
详见代码.

/*  xzppp  */
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <list>
#include <math.h>
#include <iomanip>
using namespace std;
#define FFF freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define mp make_pair
typedef long long  LL;
typedef unsigned long long ULL;
const int MAXN = 10000;
const int  INF = 0x7fffffff;
const int MOD = 1e9+7;
struct 
{
    int p1,p2,p4;
}all[MAXN+17];
int main()
{
    //FFF
    int n,k;
    cin>>n>>k;
    int h4 = n,h2 = 2*n;
    for (int i = 0; i < k; ++i)
    {
        int temp;
        cin>>temp;
        all[i].p4 = temp/4;
        temp -= all[i].p4*4;
        all[i].p2 = temp/2;
        temp -= all[i].p2*2;
        all[i].p1 = temp;
    }
    bool can = true;
    int r2=0,r1=0;
    for (int i = 0; i < k; ++i)
    {
        if(h4>=all[i].p4)
            h4 -= all[i].p4;
        else
        {
            all[i].p4 -= h4;
            h4 = 0;
            if(2*h2>=all[i].p4)
                h2 -= 2*all[i].p4;
            else
                can = false;
        }
        r2 += all[i].p2;
        r1 += all[i].p1;
    }
    if(h2>=r2)
    {
        h2 -= r2;
        r2 = 0;
    }
    else
    {
        r2 -= h2;
        h2 = 0;
    }
    if(h2>=r1)
    {
        h2 -= r1;
        r1 = 0;
    }
    else
    {
        r2 -= h2;
        h2 = 0;
    }
    if(!(h4>=r2&&r1+r2<=2*h4))
    {
        if(!(r2>h4&&(r2-h4)*2+r1<=h4))
            can = false;
    }
    if(can)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值