您的位置:首页 > 其它

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  acm codeforces