hdu1517
地址:http://acm.hdu.edu.cn/showproblem.php?pid=1517
A Multiplication Game
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2846 Accepted Submission(s): 1630
Stan wins.
or
Ollie wins.
assuming that both of them play perfectly.
162 17 34012226
Stan wins. Ollie wins. Stan wins.
#include<stdio.h>
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
__int64 i,m,n[2]={9,2},k;
while(scanf("%I64d",&m)>0)
{
i=1;k=0;
while(i<m)
{
i=i*n[k];
k=(k+1)%2;
}
if(k==1) printf("Stan wins.\n");
else printf("Ollie wins.\n");
}
return 0;
}
hdu1846
地址:http://acm.hdu.edu.cn/showproblem.php?pid=1846
Brave Game
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4571 Accepted Submission(s): 3001
今天,大家选择上机考试,就是一种勇敢(brave)的选择;这个短学期,我们讲的是博弈(game)专题;所以,大家现在玩的也是“勇敢者的游戏”,这也是我命名这个题目的原因。
当然,除了“勇敢”,我还希望看到“诚信”,无论考试成绩如何,希望看到的都是一个真实的结果,我也相信大家一定能做到的~
各位勇敢者要玩的第一个游戏是什么呢?很简单,它是这样定义的:
1、 本游戏是一个二人游戏;
2、 有一堆石子一共有n个;
3、 两人轮流进行;
4、 每走一步可以取走1…m个石子;
5、 最先取光石子的一方为胜;
如果游戏的双方使用的都是最优策略,请输出哪个人能赢。
每组测试数据占一行,包含两个整数n和m(1<=n,m<=1000),n和m的含义见题目描述。
2 23 2 4 3
first second
水方法:对于一个总数为m的石子堆,一次至多去除n个,那么当石子数目小于等于n时,必定为第一个人胜利。而当石子有n+1个时,必定为第二个人胜利,因为无论第一个人取多少个石子,必定小于n+1,而二个人一共取得石子总数一定可以组成n+1。由此推知,对于n+2,我们第一次只取一个石子,那么轮到第二个人取石子时石子堆一共有n+1个石子,又变成了刚才那种情况,所以自n+2到n+n+1都必为第一个人胜利。往下推就可得出公式。
#include<stdio.h>
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
int t,m,n,a[1010];
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&m,&n);
if(m%(n+1)==0) printf("second\n");
else printf("first\n");
}
return 0;
}
hdu1847
地址:http://acm.hdu.edu.cn/showproblem.php?pid=1847
Good Luck in CET-4 Everybody!
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3659 Accepted Submission(s): 2306
“升级”?“双扣”?“红五”?还是“斗地主”?
当然都不是!那多俗啊~
作为计算机学院的学生,Kiki和Cici打牌的时候可没忘记专业,她们打牌的规则是这样的:
1、 总共n张牌;
2、 双方轮流抓牌;
3、 每人每次抓牌的个数只能是2的幂次(即:1,2,4,8,16…)
4、 抓完牌,胜负结果也出来了:最后抓完牌的人为胜者;
假设Kiki和Cici都是足够聪明(其实不用假设,哪有不聪明的学生~),并且每次都是Kiki先抓牌,请问谁能赢呢?
当然,打牌无论谁赢都问题不大,重要的是马上到来的CET-4能有好的状态。
Good luck in CET-4 everybody!
1 3
Kiki Cici
#include<stdio.h>
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
int i,m,n,a[1010];
a[0]=2;a[1]=1;a[2]=1;
for(i=3;i<=1000;i++)
{
n=1;
while(n<=i)
{
if(a[i-n]==2)
{
a[i]=1;break;
}
a[i]=2;
n*=2;
}
}
while(scanf("%d",&m)>0)
{
if(a[m]==1) printf("Kiki\n");
else printf("Cici\n");
}
return 0;
}
hdu2147
地址:http://acm.hdu.edu.cn/showproblem.php?pid=2147
kiki's game
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 40000/1000 K (Java/Others)Total Submission(s): 5153 Accepted Submission(s): 3028
5 3 5 4 6 6 0 0
What a pity! Wonderful! Wonderful!
#include<stdio.h>
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
int m,n;
while(scanf("%d%d",&m,&n)>0,m,n)
{
if(m*n%2==0) printf("Wonderful!\n");
else printf("What a pity!\n");
}
return 0;
}
不知代码对不对,反正AC了
POJ 2484
地址:http://poj.org/problem?id=2484
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 3475 | Accepted: 2047 |
Description

Figure 1
Note: For n > 3, we use c1, c2, ..., cn to denote the coins clockwise and if Alice remove c2, then c1 and c3 are NOT adjacent! (Because there is an empty place between c1 and c3.)
Suppose that both Alice and Bob do their best in the game.
You are to write a program to determine who will finally win the game.
Input
Output
Sample Input
1 2 3 0
Sample Output
Alice Alice Bob
利用了一个模仿的思想。当硬币数小于等于2时,就是Alice赢。当硬币数在3-4之间,就是Bob赢。当硬币大于4时,Bob就对称模仿Alice,例如8个硬币按1-8标号,Alice第一次拿走了编号为1的硬币,Bob拿走对称的硬币5,若Alice拿走1,2两枚硬币,Bob就拿5,6两枚,那么最后一定是Bob胜利。
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
int m;
while(scanf("%d",&m)>0,m)
{
if(m==0) break;
if(m<=2) puts("Alice");
else puts("Bob");
}
return 0;
}
poj2348
地址:http://poj.org/problem?id=2348
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 6827 | Accepted: 2781 |
Description
25 7 11 7 4 7 4 3 1 3 1 0
an Stan wins.
Input
Output
Sample Input
34 12 15 24 0 0
Sample Output
Stan wins Ollie wins
题意:每次可以拿大的数减去小的数的倍数,但不能减到小于零,最后先得到零的人胜利。
可以推断:每次减一小的数的一倍就可以的到下一组数据时就看操作数的奇偶性,否则就看到要减多倍的那组数据的操作数的奇偶性。
#include<cstdio>
#include<cmath>
#include<iostream>
using namespace std;
int main()
{
int m,n,i;
while(scanf("%d%d",&m,&n)>0,m,n)
{
i=0;
while(m!=0)
{
if(m<n)
{
n^=m;
m^=n;
n^=m;
}
i++;
if((m/n)>1&&m%n!=0) break;
m=m%n;
}
if(i%2==1) puts("Stan wins");
else puts("Ollie wins");
}
return 0;
}