Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
绝对科学的算法,不过lte了,可能题的意思是要保留计算结果??#include<iostream> #include<cstdlib> using namespace std; int judge(int,int); int min(int,int); int main() { int a,b; while(cin>>a>>b) { cout<<judge(a,b)<<endl; } return 0; } int judge(int n,int m) { int i; if(n!=0&&m==0) return 1; if(n==0&&m!=0) return 1; if(n==0&&m==0) return 0; if(n==1&&m==0) return 1; for(i=1;i<=n;i++) { if(judge(n-i,m)==0) return 1; } for(i=1;i<=m;i++) { if(judge(n,m-i)==0) return 1; } for(i=1;i<=min(n,m);i++) { if(judge(n-i,m-i)==0) return 1; } return 0; } int min(int n,int m) { if(n<m) {return n;} return m; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator