Codeforces #839B: Game of the Row 题解

这道题巨猥琐,场上很多人都被hack了

正解应该是一个我也不知道是怎么过的贪心

首先按照人数从大到小排序

如果有四个四个的,就优先放进大横排

如果有三个三个的,也优先放进大横排,你会发现四个和三个是相似的,因为都要占用一整个大横排,或是占用两个小横排

然后是两个两个的,优先放进小横排,如果不够,优先和已经坐过一个人的大横排拼座,否则占领一个大横排

最后是一个一个的,优先和有两个人的大横排拼座,然后是占领一个大横排,最后是占领一个小横排

别问我是怎么想的,这是通过尝试能过的贪心策略

#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <utility>
#include <map>
#include <stack>
#include <set>
#include <vector>
#include <queue>
#include <deque>
#include <sstream>
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define LL long long
#define Pair pair<int,int>
#define LOWBIT(x) x & (-x)
using namespace std;

const int MOD=1e9+7;
const int INF=0x7ffffff;
const int magic=348;

int n,k;
int a[1048];
int c1,c2,c3;

bool cmp(int x,int y)
{
    return x>y;
}

int main ()
{
	int i;
	scanf("%d%d",&n,&k);
	for (i=1;i<=k;i++) scanf("%d",&a[i]);
	sort(a+1,a+k+1,cmp);
	c1=n;c2=n*2;
	for (i=1;i<=k;i++)
	{
		while (a[i]>=4 && c1>0)
		{
			c1--;
			a[i]-=4;
		}
		while (a[i]>=3 && c1>0)
		{
			c1--;
			a[i]-=3;
		}
		while (a[i]>=2 && c2>0)
		{
			c2--;
			a[i]-=2;
		}
		while (a[i]>=2 && c1>0)
		{
			c1--;
			c3++;
			a[i]-=2;
		}
		while (a[i]>0 && c3>0)
		{
			c3--;
			a[i]--;
		}while (a[i]>0 && c1>0)
		{
			c1--;
			c2++;
			a[i]--;
		}
		while (a[i]>0 && c2>0)
		{
			c2--;
			a[i]--;
		}
		
		if (a[i]>0)
		{
			printf("NO\n");
			return 0;
		}
	}
	printf("YES\n");
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值