Game of the Rows
来源:互联网 发布:et服装软件图片 编辑:程序博客网 时间:2024/05/21 07:09
http://codeforces.com/problemset/problem/839/B
分析:
这个题写的很费劲 情况分析着就乱了 大体想法是 把人数分为4、2、1 4个的需要空间4 2个和1个的都需要空间2 先把4放在中间四个位置 如果放不开就分成2的放两侧 可以放下就 YES 如果能放开中间位置还有剩下的 就判断一下有多少个2 一行最多放三个不同的2 如果剩下的行数乘以三大于2的个数或者1的个数大于剩下的行数(2和1放中间) 就YES 其他的都是NO
AC代码:
#include <bits/stdc++.h>#define gcd(a,b) __gcd(a,b)#define mset(a,x) memset(a,x,sizeof(a))#define FIN freopen("jogging.in","r",stdin)#define FOUT freopen("jogging.out","w",stdout)const int INF=0x3f3f3f3f;const double PI=acos(-1.0);const int MAX=1e5+10;typedef long long LL;const LL mod=1e9+7;using namespace std;int a[1000005];int main (){ int n,k; while (scanf ("%d%d",&n,&k)!=EOF){ for (int i=0;i<k;i++) scanf ("%d",&a[i]); int sum4=0,sum2=0,sum1=0; int sum=0; for (int i=0;i<k;i++){ if (a[i]>=4){ sum4+=a[i]/4; a[i]=a[i]%4; } if (a[i]>=2){ sum2+=a[i]/2; sum+=a[i]-a[i]%2; a[i]=a[i]%2; } if (a[i]>=1){ sum1++; sum+=2; } } if (sum4*4+sum>n*8){ printf ("NO\n");continue;} if (sum4>=n) printf ("YES\n");else{if (sum1>=n-sum4||sum2<=n*3||n*8-sum4*4-(n*3)*2-(sum1+(sum2-n*3)*2)*2>=0) printf ("YES\n");else printf ("NO\n");} } return 0;}
阅读全文
0 0
- Game of the Rows
- Game of the Rows
- cf839B Game of the rows
- Codeforces839B Game of the Rows
- Game of the Rows CodeForces
- Game of the Rows CodeForces
- CodeForces839B Game of the Rows
- codeforces 839 B Game of the Rows
- Codeforces 839B-Game of the Rows
- B. Game of the Rows(贪心)
- Codeforces 839B Game of the Rows (贪心)
- 839B Game of the Rows(水,思维,贪心)
- Codeforces 839 B. Game of the Rows (贪心)
- Codeforce 839 -- B Game of the Rows 【思维 + 贪心】
- Arya and Bran & Game of the Rows & Multiple Clocks
- Codeforces Round #428 (Div. 2) Game of the Rows (思维)
- Codeforces Round #428 (Div. 2) B. Game of the Rows
- Codeforce-839B Game of the Rows 思维
- [主席树]BZOJ 3524——[Poi2014]Couriers
- 杭电 1020 Encoding
- 从零开始搭建本地mongodb环境
- hm3-算法描述和文档
- 十一月英语学习
- Game of the Rows
- Large Pose 3D Face Reconstruction 文章理解
- 机房重构总结1
- tomcat正常启动后http://localhost:8080/报错404
- 安装GraphViz以供python调用
- Building TensorFlow on Android
- 如何用DiscoGAN学习发现跨域关系(附源代码)
- ACM 并查集
- 多文件目录下makefile文件递归执行编译所有c文件