Codeforces #839B: Game of the Row 题解
来源:互联网 发布:中国有嘻哈扒皮知乎 编辑:程序博客网 时间:2024/06/15 19:25
这道题巨猥琐,场上很多人都被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
- Codeforces #839B: Game of the Row 题解
- codeforces 839 B Game of the Rows
- Codeforces 839B-Game of the Rows
- Codeforces 839B Game of the Rows (贪心)
- Codeforces 839 B. Game of the Rows (贪心)
- Codeforces 839B Game of the Rows 贪心
- codeforces 839A 428 Div2 B Game of the Rows
- codeforces 839B Game of the Rows(思路题)
- CodeForces-839B Game of the Rows(思维、细节)
- codeforces 839b 之 Game of the Rows
- codeforces#839 B Game of the Rows 思维,贪心
- Game of the Rows codeforces 839B(贪心)
- 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(思维+贪心)
- Game of the Rows CodeForces
- Game of the Rows CodeForces
- Codeforces 813C The Tag Game 题解
- 合唱团 (线性dp)
- 微信小程序选择图片和预览图片
- STM32的USART发送数据时如何使用TXE和TC标志
- 一直想弄懂的地理坐标系与投影坐标系的区别
- c++整数和字符串转换
- Codeforces #839B: Game of the Row 题解
- HDU
- PreparedStatement 和statement的区别?
- servlet详解
- vector
- java转义符和正则表达式转义符
- 单双引号的区别,defined容易疏忽的小地方
- 数据库软删除
- 不用加号两数求和