Codeforces Round #428 (Div. 2)-贪心&模拟-B. Game of the Rows
来源:互联网 发布:淘宝助理连打只能2单 编辑:程序博客网 时间:2024/06/10 01:19
http://codeforces.com/contest/839/problem/B
给定座位, 两边两个,中间4个,要求不同队伍的不能挨着。
问你怎么排列。
发现,当有一个人时,他放在2 和4 都是可以的。效果一样。
一个2可以放一个4。
策略:先放4,然后放2,他们对下面的影响可以保存qwq
#include <bits/stdc++.h>/* 计算小于8的数量,如果是 1 2 的话,就给小的座。否则 就给大的座。模拟一下。。。大概想到的是尽可能的给4,但是错了数据。将 数据分成 三种 4 2 1.因为 他们都是一样的。*/using namespace std;const int maxn=1e4+10;int a[maxn];int main(){ int m,n; while(~scanf("%d%d",&m,&n)){ for(int i=0;i<n;i++){ scanf("%d",&a[i]); } //优先放 四人。 int sum2=m*2; int sum4=m; for(int i=0;i<n;i++){ int d=min(sum4,a[i]/4); sum4-=d; a[i]-=4*d; } sum2+=sum4; for(int i=0;i<n;i++){ int d=min(sum2,a[i]/2); sum2-=d; a[i]-=2*d; } //cout<<sum2<<endl; int sum3=sum2+sum4; for(int i=0;i<n;i++){ while(a[i]){ sum3--; a[i]--; //cout<<a[i]<<endl; } } //cout<<sum3<<endl; if(sum3>=0) puts("YES"); else puts("NO"); } return 0;}
阅读全文
0 0
- Codeforces Round #428 (Div. 2) B.Game of the Rows(贪心+炒鸡多坑的模拟)
- Codeforces Round #428 (Div. 2)-贪心&模拟-B. Game of the Rows
- Codeforces Round #428 (Div. 2) B. Game of the Rows
- Codeforces Round #428 (Div. 2) B. Game of the Rows
- Codeforces Round #428 (Div. 2) B.Game of the Rows(贪心)
- Codeforces Round #428 (Div. 2) 839B. Game of the Rows(思维+贪心)
- Codeforces Round #428 (Div. 2) B. Game of the Rows(贪心)
- Codeforces Round #428 (Div. 2) B. Game of the Rows(贪心,补题)
- Codeforces Round #428 (Div. 2) Game of the Rows (思维)
- codeforces #428 Div.2 B. Game of the Rows 贪心、思维
- Codeforces Round #428 (Div. 2) B. Game of the Rows (思维)
- CF —— Codeforces Round #428 (Div. 2) B. Game of the Rows
- Codeforces 428(div 2)B. Game of the Rows(思维题)
- Codeforces 839B Game of the Rows (贪心)
- Codeforces 839 B. Game of the Rows (贪心)
- Codeforces 839B Game of the Rows 贪心
- codeforces#839 B Game of the Rows 思维,贪心
- Game of the Rows codeforces 839B(贪心)
- Guardian of Decency UVA
- pom中的build
- Android饼状图的绘制
- vs2012创建dll
- 10种极具创意的验证码设计
- Codeforces Round #428 (Div. 2)-贪心&模拟-B. Game of the Rows
- Qt中QAction在菜单栏、工具栏、状态来上的使用及添加快捷键
- JavaScript 得到上周时间范围,本月时间范围
- 计算机视觉基础
- 记flume部署过程中遇到的问题以及解决方法(持续更新)
- JavaScript中new语句
- 支持向量机 Support Vector Machines (SVM)
- DOM及其扩展
- 六种三栏式布局