[PNポイントを求めて]poj 2505 A multilication game
2498 ワード
テーマリンク:
http://poj.org/problem?id=2505
A multication game
Time Limit: 1000 MS
メモリLimit: 65536 K
Total Submissions: 5098
Acceepted: 2573
Description
Stn and Ollie PlayStation the game of multication by multipling a n integer p by one of the numbers 2 to 9.Stn always starts with p=1、does his multiplication、then Ollie multilies the number、the and the the the the and the and the the firever.starta.starta.starta.starta.starts.starts。
Input
Each line of input contains one integer number n.
Output
For each line of input output one line eigher
スタンウィンズ.
or
Ollie wins.
asuming that both of them Playperfectly.
Sample Input
Waterloo local 2001.09.22
[Submit] [Go Back] [Sttus [ディスク
タイトルの意味:
一つのnをあげて、二人は交替でゲームをします。p=1から始まります。毎回2か9をかけることができます。初めてnに来た人が勝ちます。二人とも十分に頭がいいと仮定します。
1<n>4294967295
問題解決の考え方:
Pを探したら必ず負けます。Nが勝ちます。
コードの説明はとても詳しいです。
http://poj.org/problem?id=2505
A multication game
Time Limit: 1000 MS
メモリLimit: 65536 K
Total Submissions: 5098
Acceepted: 2573
Description
Stn and Ollie PlayStation the game of multication by multipling a n integer p by one of the numbers 2 to 9.Stn always starts with p=1、does his multiplication、then Ollie multilies the number、the and the the the the and the and the the firever.starta.starta.starta.starta.starts.starts。
Input
Each line of input contains one integer number n.
Output
For each line of input output one line eigher
スタンウィンズ.
or
Ollie wins.
asuming that both of them Playperfectly.
Sample Input
162
17
34012226
Sample Output Stan wins.
Ollie wins.
Stan wins.
SourceWaterloo local 2001.09.22
[Submit] [Go Back] [Sttus [ディスク
タイトルの意味:
一つのnをあげて、二人は交替でゲームをします。p=1から始まります。毎回2か9をかけることができます。初めてnに来た人が勝ちます。二人とも十分に頭がいいと仮定します。
1<n>4294967295
問題解決の考え方:
Pを探したら必ず負けます。Nが勝ちます。
コードの説明はとても詳しいです。
//#include<CSpreadSheet.h>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<string>
#include<string.h>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<ctime>
#include<bitset>
#include<cmath>
#define eps 1e-6
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
#define ll __int64
#define LL long long
#define lson l,m,(rt<<1)
#define rson m+1,r,(rt<<1)|1
#define M 1000000007
//#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
int n;
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
while(~scanf("%d",&n))
{
int ans=0; //
int cur=n-1;
while(cur>=1)
{
if(!ans) //
cur/=9; // cur/9+1~cur *9
else //
cur/=2; // *2
// printf("ans:%d cur:%d
",ans,cur);
//system("pause");
ans^=1;
}
if(ans)
printf("Stan wins.
");
else
printf("Ollie wins.
");
}
return 0;
}