拉题链接 https://vjudge.net/contest/430219#overview
原题链接 https://codeforces.com/problemset/problem/299/C
题目
题意
先手有2n个数字, 后手也有2n个数字, 数字为0或1, 一人拿了一个数后, 另一人也不能拿他的对应序号的数字, 看最后谁的1多
题解
x = 先手的1的个数 y = 后手的1的个数 z = 先手和后手同时有1的个数
最优策略为两个人先去拿“公共”的1,然后再去拿“自己”的1,在拿公共的1时先手会比后手多拿z%2个1,那么x=x+z%2+z/2即为先手可以拿的1的数量,y=y+z/2为后手可以拿的1的数量,注意到先手有一个优势就是如果后手恰比先手多拿一个1的话,那么先手可以先把这个1位置拿了使得后手取不到这个1把局面变成平局,所以如果y-1=x也是平局,
只有当y-x > 1时后手必胜,y-x < 0时先手必胜,y=x或y=x+1时是平局
代码
#include <iostream> #include <string> using namespace std; string a, b; int main() { int n, x = 0, z = 0, y = 0; cin >> n; cin >> a >> b; for(int i = 0; i < 2*n; i ++) { if(a[i] == '1') x ++; if(b[i] == '1') y ++; if(a[i] == '1' && b[i] == '1') z ++; } x += z % 2; if(x - y > 0) puts("First"); else if(x == y || x == y - 1) puts("Draw"); else puts("Second"); return 0; }