Game of the Rows
来源:互联网 发布:c二维数组赋值为0 编辑:程序博客网 时间:2024/05/18 01:48
题目链接:
http://codeforces.com/contest/839/problem/B
【题意】
有k个军队要坐飞机,飞机有n个机舱,每个机舱有8个座位,其中座位{1,2},{3,4},{4,5},{5,6},{7,8}是相邻的,现在是否存在一种安排座位的方法,使得不同军队的军人不坐在相邻位置。
【思路】
先考虑将4连坐安排完,坐4个,坐2+1个,坐1+1个,剩下的如果都是2还可以把2拆分成2+1。
#include<bits/stdc++.h>using namespace std;#define minn 10005int a[minn];int main(){ int n,k,z,sum; while(~scanf("%d%d",&n,&k)) { int nn=n; memset(a,0,sizeof(a)); for(int i=0;i<k;i++) { scanf("%d",&z); a[4]+=z/4; a[z%4]++; } z=min(a[4],n); a[4]-=z; n-=z; // cout<<n<<endl; a[2]+=2*a[4]; a[2]+=a[3]; a[1]+=a[3]; // cout<<a[1]<<' '<<a[2]<<endl; if(n>0) { int z=min(a[2],a[1]); z=min(z,n); n-=z; a[2]-=z; a[1]-=z; } if(n>0) { int z=min(a[1]/2*2,2*n); a[1]-=z; n-=z/2; } // cout<<"n="<<n<<endl; // cout<<a[1]<<' '<<a[2]<<endl; if(n>0) a[2]-=min(a[2],(n-a[1])/2); if(a[1]+a[2]>nn*2+max(n,0)) { cout<<"NO"<<endl; } else cout<<"YES"<<endl; }}
阅读全文
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 思维
- 写点东西
- Socket operation on non-socket 错误出现有两种情况:
- 牛顿迭代法
- JVM 内存设置大小(Xms Xmx PermSize MaxPermSize 区别)
- Spark入门(五):键值对RDD
- Game of the Rows
- Tensorflow 常用库
- 技术类小tip
- 操作系统常用调度算法
- K
- 【亲测】centos7下添加NuxDextop仓库
- HTML5-旋转木马-遮罩层-电子相册-无缝
- iOS开发之最近的小知识点总结一
- bzoj 1625: [Usaco2007 Dec]宝石手镯(01背包)