摘要: 如果n/m>1的话就Stan wins否则就球gcd,看经过多少次可以出现m==0的情况。注意的是在求gcd的过程中会出现n/m>1的情况,#include"iostream"using namespace std;int gcd(int n,int m){ int i=0; while(1) { if(n/m>1) break; i++; n-=m; if(n<m) {int tmp=m;m=n;n=tmp;} if(m==0) break; } return i;}int main(){ int n,m; while(cin>>n&g 阅读全文
posted @ 2011-05-10 13:12 Ac_smile 阅读(235) 评论(0) 推荐(0) 编辑
摘要: 简单的NIM游戏过程,就不分析了。#include"iostream"using namespace std;int main(){ int n; while(cin>>n) { int i,k,ans=0; for(i=0;i<n;i++) { cin>>k; ans^=k; } if(ans) cout<<"Yes"<<endl; else cout<<"No"<<endl; } return 0;} 阅读全文
posted @ 2011-05-10 12:26 Ac_smile 阅读(237) 评论(0) 推荐(0) 编辑
摘要: Alice and Bob decide to play a new stone game.At the beginning of the game they pick n(1<=n<=10) piles of stones in a line. Alice and Bob move the stones in turn.At each step of the game,the player choose a pile,remove at least one stones,then freely move stones from this pile to any other pil 阅读全文
posted @ 2011-05-10 12:18 Ac_smile 阅读(231) 评论(0) 推荐(0) 编辑
摘要: N堆取石子,取完最后者输。有个叫SJ定理。#include"iostream"using namespace std;int main(){ int t; cin>>t; while(t--) { int s[50],n; cin>>n; int i,flag=0,ans=0; for(i=0;i<n;i++) { cin>>s[i]; ans^=s[i]; if(s[i]>1) flag=1; } if(!flag) { if(n%2==0) cout<<"John"<<endl; 阅读全文
posted @ 2011-05-09 21:18 Ac_smile 阅读(319) 评论(0) 推荐(0) 编辑
摘要: /*典型的SG函数的应用。求出SG值之后一连串的异或就好了*/#include"iostream"#include"algorithm"#include"string.h"using namespace std;int s[101],sg[10001],k;int getsg(int m){ int hash[101]={0}; int i; for(i=0;i<k;i++){ if(m-s[i]<0) break; if(sg[m-s[i]]==-1) sg[m-s[i]]=getsg(m-s[i]); hash[sg[ 阅读全文
posted @ 2011-05-09 12:38 Ac_smile 阅读(622) 评论(0) 推荐(0) 编辑
摘要: 计算几何头疼的地方一般在于代码量大和精度问题,代码量问题只要平时注意积累模板一般就不成问题了。精度问题则不好说,有时候一个精度问题就可能成为一道题的瓶颈,简直“画龙点睛”。这些年的题目基本是朝着越来越不卡精度的方向发展了,但是也不乏一些%^&%题#$%$^,另外有些常识不管题目卡不卡,都是应该知道的。今天我就开膛回顾下见过且还有印象的精度问题,由于本人见识和记忆均有限,望各位大神瞄过后不吝补充。另外,为了弥补我匮乏的文思,我可能乱扯些不太相关或者尽人皆知的东西凑数。那么,现在开始。计算几何的精度问题说到底其实是浮点数的精度问题,但我觉得“计算几何”比“浮点数”更能吸引眼球,所以选了这个 阅读全文
posted @ 2011-05-09 10:44 Ac_smile 阅读(2073) 评论(0) 推荐(3) 编辑
摘要: 给出N只老鼠,两种杀法:1,一次杀一只;2,奇数的话就杀(n-1)/2只,偶数的话就杀n/2只。Alice和Bob轮流进行,Alice kill first。谁杀完最后一只老鼠者胜。第一次见这样的博弈,其实是要用模拟的思想再加上博弈的思想。#include"iostream"using namespace std;int main(){ int t; cin>>t; while(t--) { int n; cin>>n; if(n==1) { cout<<"Alice"<<endl; continue; } 阅读全文
posted @ 2011-05-08 22:26 Ac_smile 阅读(229) 评论(1) 推荐(1) 编辑
摘要: 题意是:求出满足2^x mod n = 1的x。这样的x叫做2模n的次数。我使用余数的性质递推的,应该还有好的算法。#include"stdio.h" int main() { int n; while(scanf("%d",&n)!=EOF) { if(n==1||n%2==0) { printf("2^? mod %d = 1\n",n);continue;} int ans,k=1;long long s=2; ans=s%n; while(ans!=1) { s=ans*2; ans=s%n; k++; } print 阅读全文
posted @ 2011-05-05 14:55 Ac_smile 阅读(174) 评论(0) 推荐(0) 编辑
摘要: 求在N中取M的个数,简单的组合数。#include"iostream" using namespace std; int main() { int n,k; while(cin>>n>>k,n!=0||k!=0) { if(n-k<k)//根据组合数的公式尽量约去大的部分 k=n-k; int count=k; __int64 ans=1; while(count--) { ans*=n--; while(ans%k==0&&k>1)//组合数结果一定是整数 { ans/=k; k--; } } printf(" 阅读全文
posted @ 2011-05-04 22:58 Ac_smile 阅读(278) 评论(0) 推荐(0) 编辑
摘要: Write a program to convert numbers in one base to numbers in a second base. There are 62 different digits: { 0-9,A-Z,a-z } HINT: If you make a sequence of base conversions using the output of one conversion as the input to the next, when you get back to the original base, you should get the original 阅读全文
posted @ 2011-05-04 15:31 Ac_smile 阅读(586) 评论(0) 推荐(1) 编辑