Codeforces
来源:互联网 发布:php 循环拼接字符串 编辑:程序博客网 时间:2024/06/07 11:23
Weird Game
题目链接
分类:贪心
1.题意概述
- AB各有长度为2n的01串,每次轮流在1~2n里选一个之前双方没选过的数,那么他可以得到他的串里对应位置的数字。 最后AB各得到n个数字,他们将其任意排列后做比较。若双方都是最优策略,问你谁会赢?
2.解题思路
- 我们这样考虑如果一个位置双方都是1,显然两个人都优先选这个,因为不想让对方得到更多的1。又由于A先手,它取完所能取的1以后,A接下来考虑的肯定是不让B拿到更多的1,因此他会取A为0但B为1的位置,最后才是双方都为0的位置。接下来贪心地模拟就行!
- 模拟时候注意,由于A先手,如果A取完它所有的1以后B还有一个1,那么A可以取走对于位置的0,双方1个数还是相等,此时依然平局!
3.AC代码
#include <bits/stdc++.h>#define INF 0x3f3f3f3f#define maxn 2001000#define lson root << 1#define rson root << 1 | 1#define N 1111#define eps 1e-6#define pi acos(-1.0)#define e exp(1.0)using namespace std;const int mod = 1e9 + 7;typedef long long ll;typedef unsigned long long ull;char ch[2][maxn];int main(){#ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); long _begin_time = clock();#endif int n; while (~scanf("%d", &n)) { scanf("%s%s", ch[0], ch[1]); int a = 0, b = 0, cnt = 0; n *= 2; for (int i = 0; i < n; i++) { if (ch[0][i] == '1' && ch[1][i] == '1') cnt++; else if (ch[0][i] == '1') a++; else if (ch[1][i] == '1') b++; } cnt %= 2; //剩下的双1个数 if (b - 1 == cnt + a) b--; a += cnt; if (a > b) puts("First"); else if (a < b) puts("Second"); else puts("Draw"); }#ifndef ONLINE_JUDGE long _end_time = clock(); printf("time = %ld ms.", _end_time - _begin_time);#endif return 0;}
阅读全文
0 0
- codeforces~~~
- Codeforces
- codeforces
- Codeforces
- codeforces
- codeforces
- Codeforces
- Codeforces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- Python随记(二)字符串
- Python分割训练集和测试集
- Linux线程创建以及回调函数的使用
- log4j日志配置详解
- Shell传递参数~03
- Codeforces
- IIS Could not load type ‘System.ServiceModel.Activation.HttpModule’ from assembly ‘System.ServiceMo
- echart实现数据库取值绘制三种类型的图
- 浏览器缓存知识小结及应用
- ZOJ
- eclipse中查看jar包中的源码
- BRD、MRD 和 PRD
- 最小生成树
- zoj1093 Monkey and Banana 动态规划