UVa 10404. Bachet's Game
来源:互联网 发布:超强手机振动器软件 编辑:程序博客网 时间:2024/06/06 09:22
题意为给出总石子数n,和m堆石子,两个人轮着取石子,每次只能从总石子中取m堆中的一堆的个数的石子,取走最后一个石子的胜。S先取,O后取。
用博弈的输赢观念+dp就可以了,由于记忆化搜索会爆栈,那就递推了,索性还好推……
不然就不会了……
#include<iostream>#include<map>#include<string>#include<cstring>#include<cstdio>#include<cstdlib>#include<cmath>#include<queue>#include<vector>#include<algorithm>using namespace std;int dp[1000010];int a[20];int n,m;int main(){int i,j;while(cin>>n>>m){for(i=0;i<m;i++)cin>>a[i];for(i=0;i<=n;i++){dp[i]=0;for(j=0;j<m;j++)if(i-a[j]>-1&&dp[i-a[j]]==0){dp[i]=1;continue;}}if(dp[n]==1)cout<<"Stan wins"<<endl;elsecout<<"Ollie wins"<<endl;}}
Bachet's Game
Time Limit:6666MS Memory Limit:Unknown 64bit IO Format:%lld & %llu
Description
Problem B: Bachet's Game
Bachet's game is probably known to all but probably not by this name. Initially there aren stones on the table. There are two players Stan and Ollie, who move alternately. Stan always starts. The legal moves consist in removing at least one but not more thank stones from the table. The winner is the one to take the last stone.Here we consider a variation of this game. The number of stones that can be removed in a single move must be a member of a certain set ofm numbers. Among the m numbers there is always 1 and thus the game never stalls.
Input
The input consists of a number of lines. Each line describes one game by a sequence of positive numbers. The first number isn <= 1000000 the number of stones on the table; the second number ism <= 10 giving the number of numbers that follow; the last m numbers on the line specify how many stones can be removed from the table in a single move.Input
For each line of input, output one line saying either Stan wins or Ollie wins assuming that both of them play perfectly.Sample input
20 3 1 3 821 3 1 3 822 3 1 3 823 3 1 3 81000000 10 1 23 38 11 7 5 4 8 3 13999996 10 1 23 38 11 7 5 4 8 3 13
Output for sample input
Stan winsStan winsOllie winsStan winsStan winsOllie wins
Problem Setter: Piotr Rudnicki
Source
Root :: Competitive Programming 3: The New Lower Bound of Programming Contests (Steven & Felix Halim) :: Mathematics :: Game Theory ::Standard
Root :: AOAPC I: Beginning Algorithm Contests (Rujia Liu) :: Volume 5. Dynamic Programming
Root :: Competitive Programming 2: This increases the lower bound of Programming Contests. Again (Steven & Felix Halim) :: Mathematics ::Game Theory - Standard
Root :: Prominent Problemsetters :: Piotr Rudnicki
Root :: AOAPC I: Beginning Algorithm Contests (Rujia Liu) :: Volume 5. Dynamic Programming
Root :: Competitive Programming 2: This increases the lower bound of Programming Contests. Again (Steven & Felix Halim) :: Mathematics ::Game Theory - Standard
Root :: Prominent Problemsetters :: Piotr Rudnicki
0 0
- UVa 10404. Bachet's Game
- UVa 10404. Bachet's Game
- uva 10404 Bachet's Game
- UVA 10404 Bachet's Game
- UVa 10404 - Bachet's Game
- UVa 10404 - Bachet's Game
- uva 10404 - Bachet's Game
- UVa 10404 - Bachet's Game
- UVa 10404 - Bachet's Game
- Uva-10404-Bachet's Game
- UVa:10404 Bachet's Game
- UVA - 10404 Bachet's Game
- UVa 10404 - Bachet's Game
- uva 10404 Bachet's Game
- UVA 10404 Bachet's Game
- UVA-10404-Bachet's Game
- UVA 10404 Bachet's Game
- UVA 10404 Bachet's Game
- Trail: JDBC(TM) Database Access(3)
- 如何实现团队的自组织管理
- 技术团队新官上任之基层篇
- 怎样下载完整的Spring包
- Myeclipse2014 自带的报表功能 与 Eclipse BIRT
- UVa 10404. Bachet's Game
- 用Java批量下载人教网电子课本和教师用书
- 初次使用Rubymine
- php中mysql和mysqli 还有PDO关系区别
- java cookie
- GCD教程(一):基本概念
- HDU 5122 K.Bro Sorting
- 在Netbeans中集成Composer管理PHP项目依赖
- Unity学习之继承和多态