Codeforces - 299C. Weird Game - 贪心、博弈
2017-07-14 10:08
351 查看
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; }
相关文章推荐
- Codeforces_388C_Fox and Card Game(博弈、贪心、排序)
- 【Codeforces 578B】【贪心】"Or" Game
- codeforces389 E. Fox and Card Game【博弈 + 贪心】
- codeforces 850C Arpa and a game with Mojtaba(博弈,bitmask)
- HDU 4023 (博弈 贪心 模拟) Game
- Codeforces 755-B. PolandBall and Game(贪心)
- CodeForces 630 R. Game【博弈】
- codeforces 777 BGame of Credit Cards(贪心)
- [Codeforces 451A] Game With Sticks (博弈)
- Codeforces Round #432 (Div. 2) (Codeforces 850C) E. Arpa and a game with Mojtaba 博弈+状态压缩
- codeforces 462 B.Appleman and Card Game (贪心)
- CodeForces - 755B PolandBall and Game ( 贪心 博弈 )
- HDU-4647 Another Graph Game 贪心,博弈
- Codeforces 578B Or Game [贪心] [位运算]
- codeforces 399 E. Game of Stones 博弈 思维题
- 【Codeforces 765 C. Table Tennis Game 2】+ 贪心
- codeforces 549C C. The Game Of Parity(博弈)
- Codeforces 579D "Or" Game【贪心+暴力按位处理】
- CodeForces 595C Warrior and Archer(贪心博弈)
- [Easy] CodeForces - 897D Ithea Plays With Chtholly | 贪心博弈