04 2012 档案

摘要:#include#include#include#define N 1000005using namespace std;int position[N];int main(){ memset(position,0,sizeof(position)); position[1]=0; int next=1; int i,j; for(i=2;i<N;i++) { if(position[i]) continue; for(j=i;j<N;j+=i) { position[j]=next; } next++; } int m; while(scanf("%d",&am 阅读全文
posted @ 2012-04-28 21:54 剑不飞 阅读(442) 评论(0) 推荐(0)
摘要:How many prime numbersTime Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3302 Accepted Submission(s): 1074Problem DescriptionGive you a lot of positive integers, just to find out how many prime numbers there are.InputThere are a lot of cases. In eac. 阅读全文
posted @ 2012-04-28 20:35 剑不飞 阅读(212) 评论(0) 推荐(0)
摘要:公式 p+q-gcd(p,q)就是所求值#include#include#includeusing namespace std;int gcd(int n,int m){ if(m==0) return n; gcd(m,n%m);}int main(){ int m,n; while(cin>>m>>n) { cout<<m+n-gcd(m,n)<<endl; }} 阅读全文
posted @ 2012-04-28 17:48 剑不飞 阅读(88) 评论(0) 推荐(0)
摘要:Transformations A square pattern of size N x N (1 #include #include #include #define N 15 using namespace std; char map[N][N]; char _map[N][N]; int main() { freopen("transform.in","r",stdin); freopen("transform.out","w",stdout); int m; while(scanf("%d&quo 阅读全文
posted @ 2012-04-28 13:48 剑不飞 阅读(145) 评论(0) 推荐(0)
摘要:Milking CowsThree farmers rise at 5 am each morning and head for the barn to milk three cows. The first farmer begins milking his cow at time 300 (measured in seconds after 5 am) and ends at time 1000. The second farmer begins at time 700 and ends at time 1200. The third farmer begins at time 1500 a 阅读全文
posted @ 2012-04-27 20:46 剑不飞 阅读(260) 评论(0) 推荐(0)
摘要:Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2000 Accepted Submission(s): 1423Problem Description假设有x1个字母A, x2个字母B,..... x26个字母Z,同时假设字母A的价值为1,字母B的价值为2,..... 字母Z的价值为26。那么,对于给定的字母,可以找到多少价值 #include using namespace std; int f[55],word[27],cun[55]. 阅读全文
posted @ 2012-04-25 20:17 剑不飞 阅读(190) 评论(0) 推荐(0)
摘要:Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3001 Accepted Submission(s): 1868Problem DescriptionA friend of you is doing research on the Traveling Knight Problem (TKP) where you are to find the shortest closed tour of knight moves that visits 阅读全文
posted @ 2012-04-25 17:32 剑不飞 阅读(154) 评论(0) 推荐(0)
摘要:Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3266 Accepted Submission(s): 1519Problem DescriptionA robot has been programmed to follow the instructions in its path. Instructions for the next direction the robot is to move are laid down in a gri 阅读全文
posted @ 2012-04-25 16:21 剑不飞 阅读(165) 评论(0) 推荐(0)
摘要:Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)Total Submission(s) : 2 Accepted Submission(s) : 2Font: Times New Roman | Verdana | GeorgiaFont Size: ← →Problem DescriptionEddy's interest is very extensive, recently he is interested in prime number. Eddy discover th 阅读全文
posted @ 2012-04-14 11:02 剑不飞 阅读(143) 评论(0) 推荐(0)
摘要:Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)Total Submission(s) : 4 Accepted Submission(s) : 3Font: Times New Roman | Verdana | GeorgiaFont Size: ← →Problem Description哥德巴赫猜想大家都知道一点吧.我们现在不是想证明这个结论,而是想在程序语言内部能够表示的数集中,任意取出一个偶数,来寻找两个素数,使得其和等于该偶数.做好了这件实事,就能说明这个猜想是成立的.由于 阅读全文
posted @ 2012-04-14 10:30 剑不飞 阅读(188) 评论(0) 推荐(0)
摘要:素数判定 Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)Total Submission(s) : 8 Accepted Submission(s) : 2Font: Times New Roman | Verdana | GeorgiaFont Size: ← →Problem Description对于表达式n^2+n+41,当n在(x,y)范围内取整数值时(包括x,y)(-39 #include #define N 4004 using namespace std; bool i 阅读全文
posted @ 2012-04-14 10:08 剑不飞 阅读(177) 评论(0) 推荐(0)
摘要:计算大素数因子#include #include #define N 20004 using namespace std; int isp[N]; int main() { int m,n,max,ans; memset(isp,0,sizeof(isp)); isp[1]=1; for(int i=2;i>m) { max=0; for(int i=0;i>n; if(isp[n]>max) { max=isp[n]; ans=n; } } cout<<ans<<endl; }... 阅读全文
posted @ 2012-04-14 09:08 剑不飞 阅读(138) 评论(0) 推荐(0)
摘要:/*ID:nealgav1 PROG:friday LANG:C++ */ #include #include #define N 403 int week[N][7]; void search() { memset(week,0,sizeof(week)); int i,j,k,year,ri,count=0; bool flag=0; for(i=1900,year=0;i<1900+N;i++,year++) { if(year) {for(int zz=0;zz<7;zz++) week[year][zz]=week[year-1][zz]; ... 阅读全文
posted @ 2012-04-11 20:29 剑不飞 阅读(125) 评论(0) 推荐(0)
摘要:简单题,建个结构体/*ID:nealgav1 PROG:gift1 LANG:C++ */ #include #include #define N 2004 class people { public: char name[20]; int money; }; int m; people name[N]; int getid(char name_[]) { for(int i=0;i<m;i++) { if(strcmp(name[i].name,name_)==0) return i; } } int main() { freopen("gift1... 阅读全文
posted @ 2012-04-07 20:54 剑不飞 阅读(149) 评论(0) 推荐(0)
摘要:简单题,不解释,就是要注意提交格式。/*ID: nealgav1 PROG: ride LANG: C++ */ #include #include int main() { freopen("ride.in","r",stdin); freopen("ride.out","w",stdout); char name[10],q[10]; int i,j,lenn,lenq; while(scanf("%s%s",name,q)!=EOF) { lenn=strlen(name); lenq=s 阅读全文
posted @ 2012-04-07 19:37 剑不飞 阅读(147) 评论(0) 推荐(0)
摘要:简单博弈就那样,懂SG函数就成,最近做的博弈都千篇一律。。。#include #include #define N 11110 int sg[N],s[N],m,n; bool h[N]; void ssgg() { int i,j; sg[0]=0; for(i=1;i=0) { h[sg[i-j]]=1; } } for(j=0;j<N;j++) { if(h[j]==0) { sg[i]=j; break; } } } } int m... 阅读全文
posted @ 2012-04-05 20:37 剑不飞 阅读(180) 评论(0) 推荐(0)
摘要:博弈题,记住SG函数值是唯一的,所以只有在n>=m时可以有多种选法所以只需在平常的博弈中加个IF(N>=m)就行了#include #include #define N 1111 int sg[N],s[N],m,n; bool h[N]; void ssgg() { int i,j; sg[0]=0; for(i=1;i=0) { h[sg[i-j]]=1; } } for(j=0;j=m) {for(i=m;i<=n;i++) { printf("%d",i); if(i!=n) ... 阅读全文
posted @ 2012-04-05 20:23 剑不飞 阅读(127) 评论(0) 推荐(0)
摘要:超简单题用上^就行了,详细见NIM游戏小NIM#include int main() { int m,s; while(scanf("%d",&m)&&m) { int ans=0; for(int i=0;i<m;i++) { scanf("%d",&s); ans^=s; } if(ans) printf("Rabbit Win!\n"); else printf("Grass Win!\n"); } } 阅读全文
posted @ 2012-04-04 16:47 剑不飞 阅读(127) 评论(0) 推荐(0)
摘要:没什么好说的,博弈简单题,懂得SG改下s数组大体都一样详细讲解类试题1850#include #include #include using namespace std; int n,m,p,sg[1003],h[1003],s[20]; void Sg() { int i,j; for(i=0;i=0)h[sg[i-s[j]]]=1; for(j=0;j<1003;j++) if(h[j]==0) { sg[i]=j; break; } } } int main() { s[0]=1;s[1]=2; for(int ... 阅读全文
posted @ 2012-04-04 16:21 剑不飞 阅读(170) 评论(0) 推荐(0)
摘要:#include #include #include using namespace std; int n,m,sg[1003],h[1003],s[14]; void Sg() { int i,j; for(i=0;i=0)h[sg[i-s[j]]]=1; for(j=0;j<1003;j++) if(h[j]==0) { sg[i]=j; break; } } } int main() { for(int i=0;i<14;i++) s[i]=1<<i; while(scanf("%d",&n)!=EOF) ... 阅读全文
posted @ 2012-04-04 15:54 剑不飞 阅读(144) 评论(0) 推荐(0)
摘要:简单博弈,懂得SG函数就能A#include #include #include using namespace std; int main() { int n,m,sg[1003],h[1003]; scanf("%d",&m); while(m--) { int i,j,k; scanf("%d%d",&n,&k); for(i=0;i=0)h[sg[i-j]]=1; } for(j=0;j<1002;j++) { if(h[j]==0) {sg[i]=j;break;} ... 阅读全文
posted @ 2012-04-04 15:15 剑不飞 阅读(122) 评论(0) 推荐(0)
摘要:SG函数的应用加上^.#include #include #include #define N 10003 using namespace std; int sg[N]; int s[103],h[103]; int main() { int n,m,i,j; //freopen("1.txt","w",stdout); while(scanf("%d",&n)&&n) { for(i=0;i=0) h[sg[j-s[i]]]=1; } for(i=0;i=s[i]&&!sg[j-s[i]]){ 阅读全文
posted @ 2012-04-04 14:53 剑不飞 阅读(134) 评论(0) 推荐(0)
摘要:pnpnpnpnpnnnnnnnnnpnpnpnpnpnnnnnnnnnpnpnpnpnpnnnnnnnnnpnpnpnpnpnnnnnnnnnpnpnpnpnp步骤1:将所有终结位置标记为必败点(P点);步骤2: 将所有一步操作能进入必败点(P点)的位置标记为必胜点(N点)步骤3:如果从某个点开始的所有一步操作都只能进入必胜点(N点) ,则将该点标记为必败点(P点) ;步骤4: 如果在步骤3未能找到新的必败(P点),则算法终止;否则,返回到步骤2。由表知当n,m均为奇数是为p-必败点#include int main() { int m,n; while(scanf("%d%d&q 阅读全文
posted @ 2012-04-04 10:15 剑不飞 阅读(117) 评论(0) 推荐(0)
摘要:经典的博弈题啊,必须弄懂必败点条件。这里是对n堆的牌数去异或,如果值为0则表示必败。题目问我们第一布有哪几种方法胜利。即就是第一步能够给对手构建多少个必败点。由于一次只能对一堆排进行操作,假设我 操作第i堆牌(a张),抽出x张。那么其余n-1堆牌的异或值是固定为b.那么 (a - x)^ b == 0 时,对手必败。到此可能有人像我一样觉得必须历遍所有a求出那个值x满足条件。其实不必要由上式可知x只有唯一取值而且 一个数 与 b 异或等于 0 即表明 这个数等于b.所以反过来我们可以求出b, 令 a - x = b ;只要b满足 b int main() { int sum,a,b[10... 阅读全文
posted @ 2012-04-04 09:52 剑不飞 阅读(167) 评论(0) 推荐(0)