CodeForces 299 C.Weird Game(博弈论)
来源:互联网 发布:乐清人民法院淘宝拍卖 编辑:程序博客网 时间:2024/05/17 18:13
Description
两个长度为2n的01串,两个人轮流开始取数字,每次只能取两个人之前都没取过的位置的数字,n次后两个人就得到了两个长度为n的数字,谁的数字大谁赢,两个人足够机智,问是先手必胜还是后手必胜还是平局
Input
第一行一整数n,之后两个长度为2n的01串(1<=n<=1e6)
Output
如果先手必胜则输出First,如果后手必胜则输出Second,如果平局则输出Draw
Sample Input
2
0111
0001
Sample Output
First
Solution
谁拿的1多谁就赢,所以去分析最优情况下两个人可以拿到的最多的1的数量,令
cnt1:第一个串是1第二个串是0的位置数
cnt2:第一个串是0第二个串是1的位置数
cnt3:第一个串是1第二个串是1的位置数
最优策略为两个人先去拿“公共”的1,然后再去拿“自己”的1,在拿公共的1时先手会比后手多拿cnt3%2个1,那么cnt1=cnt1+cnt3%2+cnt3/2即为先手可以拿的1的数量,cnt2=cnt2+cnt3/2为后手可以拿的1的数量,注意到先手有一个优势就是如果后手恰比先手多拿一个1的话,那么先手可以先把这个1位置拿了使得后手取不到这个1把局面变成平局,所以如果cnt2-1=cnt1也是平局,只有当cnt2-cnt1 > 1时后手必胜,cnt2-cnt1 < 0时先手必胜,cnt2=cnt1或cnt2=cnt1+1时是平局
Code
#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>#include<cmath>#include<vector>#include<queue>#include<map>#include<set>#include<ctime>using namespace std;typedef long long ll;#define INF 0x3f3f3f3f#define maxn 2111111int n;char a[maxn],b[maxn];int main(){ while(~scanf("%d",&n)) { scanf("%s",a); scanf("%s",b); int cnt1=0,cnt2=0,cnt3=0; for(int i=0;i<2*n;i++) { if(a[i]=='1'&&b[i]=='1')cnt3++; else if(a[i]=='1')cnt1++; else if(b[i]=='1')cnt2++; } cnt1+=cnt3%2; if(cnt2-1==cnt1)cnt2--; if(cnt1>cnt2)printf("First\n"); else if(cnt1==cnt2)printf("Draw\n"); else printf("Second\n"); } return 0;}
阅读全文
0 0
- CodeForces 299 C.Weird Game(博弈论)
- CodeForces 293A Weird Game
- CodeForces 630 R. Game(博弈论)
- 博弈论 —— The Game of Parity ( CodeForces 549C )
- CodeForces 317 D.Game with Powers(博弈论)
- Nim Game (博弈论)
- poj_1082_Calendar Game(博弈论)
- Codeforces 603C 博弈论 + 关于博弈论理解
- 【CodeForces 779B】Weird Rounding(模拟)
- codeforces 788B Weird journey (欧拉路)
- codeforces 788B Weird journey (欧拉路)
- Hdu Stone Game ( 博弈论 )
- HDU1846(博弈论,Brave Game)
- CodeForces 55 C.Pie or die(博弈论)
- 博弈论---Game!
- [博弈论] Codeforces Gym 101190 NEERC 16 G. Game on Graph
- codeforces 214C Game
- 【CODEFORCES】 C. 24 Game
- matlab小程序:求矩阵的行列式
- 如何取消选择easyui-combogrid的下拉数据
- maven使用TestNG
- 错排列
- map()和reduce()的细节
- CodeForces 299 C.Weird Game(博弈论)
- PAT B1009.说反话
- SQL Server监控
- java菜鸟之路
- 《TP5.0学习笔记---URL和路由篇》
- 大数据--一致性哈希算法
- SVG动态生成的子元素,同时绑定"click"和"dblclick".
- spring 整合 redis,以及spring的RedisTemplate如何使用
- golang中使用go时出现的的问题