Codeforces #839A: Arya and Bran 题解

这题直接模拟就好了

将这天能得到的糖果加进计数器,如果当天多于8个就给八个,否则给光

n天后,看能否给出不少于k个的糖果

#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++)
		if (a[i]/4<=c1)
		{
			c1-=a[i]/4;
			a[i]%=4;
		}
		else
		{
			a[i]-=c1*4;
			c1=0;
			break;
		}
	if (c1!=0)
	{
		for (i=1;i<=k;i++)
		{
			if (a[i]==3)
			{
				c1--;
				a[i]=0;
			}
			if (c1==0) break;
		}
		if (c1!=0)
		{
			for (i=1;i<=k;i++)
			{
				if (a[i]==2)
				{
					c2--;
					a[i]=0;
				}
				if (c2==0) break;
			}
			if (c2!=0)
			{
				c2+=2*c1;
				for (i=1;i<=k;i++)
					if (a[i]>0) c2--;
				if (c2<0)
				{
					printf("NO\n");
				}
				else
				{
					printf("YES\n");
				}
				return 0;
			}
			else
			{
				int cc1=c1;
				for (i=1;i<=k;i++)
					if (a[i]==2)
					{
						c1--;
						a[i]=0;
					}
				if (c1<0)
				{
					printf("NO\n");
					return 0;
				}
				for (i=1;i<=k;i++)
					if (a[i]>0) c1--;
				if (c1<0)
				{
					printf("NO\n");
					return 0;
				}
				printf("YES\n");
				return 0;
			}
		}
		else
		{
			for (i=1;i<=k;i++)
				if (a[i]!=0)
				{
					if (a[i]%2==0) c2-=(a[i]+1)/2; else c2-=a[i]/2;
				}
			if (c2<0)
			{
				printf("NO\n");
			}
			else
			{
				printf("YES\n");
			}
		}
	}
	else
	{
		for (i=1;i<=k;i++)
			if (a[i]!=0)
			{
				if (a[i]%2==0) c2-=(a[i]+1)/2; else c2-=a[i]/2;
			}
		if (c2<0)
		{
			printf("NO\n");
		}
		else
		{
			printf("YES\n");
		}
	}*/
	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 && c2>0)
		{
			c2--;
			a[i]--;
		}
		while (a[i]>0 && c1>0)
		{
			c1--;
			c2++;
			a[i]--;
		}
		if (a[i]>0)
		{
			printf("NO\n");
			return 0;
		}
	}
	printf("YES\n");
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值