HDU3951_Coin Game
来源:互联网 发布:乐安全软件 编辑:程序博客网 时间:2024/04/29 04:50
Coin Game
Problem Description
一堆n个硬币围成一圈,两个人轮流拿走连续k个硬币,拿走最后一堆的人获胜
问你第一个人获胜还是第二个
思路:
这是NIM游戏改编版本
但是道理都一样,俗称模仿游戏
这里有一个特例,k==1的时候输赢已经确认了,因为此时,他们都不能改变自己拿的个数
k>1的时候,无论第一个怎么拿,第二个都能拿走若干个,并且使拿走之后的硬币成偶数堆,并且完全对称
举一个例子,如果n为奇数,那么第一个人拿了m个,第二个人只需要拿m-1就行了,能使之后的状态对称偶数堆
其他类似同理
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<string>#include<queue>#include<cstdlib>#include<algorithm>#include<stack>#include<map>#include<queue>#include<vector>using namespace std;const int maxn = 1e5+100;#define pr(x) cout << #x << " = " << x << " ";#define prln(x) cout << #x << " = " << x <<endl;typedef long long ll;int main(){#ifdef LOCAL freopen("in.txt","r",stdin); // freopen("out.txt","w",stdout); #endif int n,k, kase =0; int t;cin >> t; while(t--) { cin >> n >> k; int ok = 0; if(k == 1){ if(n&1) ok = 0; else ok = 1; } else { if(k>=n) ok = 0; else ok = 1; } if(ok == 1) printf("Case %d: second\n",++kase); else if(ok == 0) printf("Case %d: first\n",++kase); } return 0;}
0 0
- HDU3951_Coin Game
- game
- game
- game
- game...
- Game
- Game
- Game
- Game
- game
- Game
- Game
- game
- game
- Game
- GAME
- Game
- Game
- 2015苹果发布会观后感
- [LeetCode] Remove Duplicates from Sorted List - 链表问题
- UVA1608_Non-boring sequences
- UVA1442_Cave
- spring mvc的图片上传与显示
- HDU3951_Coin Game
- Gif 在线制作
- LeetCode Populating Next Right Pointers in Each Node II
- magento 中文店铺设置
- Item 24:用非成员函数来支持所有元的类型转换 Effective C++笔记
- Spring管理filter和servlet
- leetcode 279: Perfect Squares
- ACM-括号匹配问题
- 9.8学习总结