Codeforces 549C The Game Of Parity【博弈】
来源:互联网 发布:天健医疗软件 编辑:程序博客网 时间:2024/05/24 06:15
C语言纠错大赛的一道题,正好拿来补博弈~~
给的代码写的略奇葩。。不过还是直接在上面改了。。
题目链接:
http://codeforces.com/problemset/problem/549/C
题意:
给你n个数,两个人依次拿走一个数,最后剩下的k个数的和若为奇数,则先手赢,否则后手赢。问谁赢?
分析:
看最后依次操作:此时有
最后一次操作是先手,则
- 剩下的全为偶数,先手必输
- 剩下的全为奇数且数字个数为偶数,拿走一个后,先手赢,否则后手赢。
- 剩下的数有奇有偶,则先手在奇数偶数中随便选一个必可以使最后和为奇数,先手赢。
最后一次操作是后手,则
- 情况与先手正好相反,但是注意有奇有偶的情况,后手肯定有办法使得剩下的和为偶数,所以还是后手赢。
- 就只有剩下的全为奇数且个数也为偶数的时候,后手才会输。。。
代码:
#include<algorithm>#include<cstdio>using namespace std;int n1,n2,n,k,even,odd,i,c,f;int Solve(){ if (n==k) return odd % 2; if (n1>n2){//s if (n2>=odd) return 0; if (n2<even) return 1; return k % 2;//修改的部分 } else{ if (n1>=even) return k % 2;//修改的部分 return 0; }}int main(){ while (scanf("%d%d",&n,&k)==2){ odd=0; even=0; n1=(n-k+1)/2; n2=(n-k)/2; for (i=1;i<=n;i++){ scanf("%d",&c); if (c % 2) odd++; else even++; } f=Solve(); if (f) printf("Stannis\n"); else printf("Daenerys\n"); } return 0;}
0 0
- codeforces 549C C. The Game Of Parity(博弈)
- Codeforces 549C. The Game Of Parity 博弈
- Codeforces 549C The Game Of Parity【博弈】
- 博弈论 —— The Game of Parity ( CodeForces 549C )
- codeforces Looksery Cup 2015 C. The Game Of Parity
- Looksery Cup 2015 C. The Game Of Parity —— 博弈
- codeforces549CThe Game Of Parity+博弈
- Codeforces549C - The Game Of Parity
- *Looksery Cup 2015 C. The Game Of Parity
- codeforces 298 C Parity Game 思维问题
- Codeforces #180 div2 C Parity Game
- codeforces--C. Predict Outcome of the Game
- The Game of 31 (博弈)
- codeforces C. Beaver Game 博弈
- Codeforces 768E Game of Stones 博弈
- 298C Parity Game
- Codeforces #258 (Div. 2) C. Predict Outcome of the Game
- Codeforces 451C Predict Outcome of the Game
- 欢迎使用CSDN-markdown编辑器
- java 垃圾回收机制
- Dalvik与JVM的区别
- windows客户端开发--xmpp协议gloox库
- APP控制网络连接速率,实现网络情况复现 ATC原理
- Codeforces 549C The Game Of Parity【博弈】
- BestCoder Round #75
- 网络命令一览表
- 一看就懂系列之 php设计模式(二)
- C++最常见面试题解答
- 理论概念方法
- LeetCode110—Balanced Binary Tree
- OpenStack笔记
- 大牛C++编程开发学习建议50条http://blog.csdn.net/gggg_ggg/article/details/44015409