上一页 1 ··· 12 13 14 15 16 17 18 19 20 ··· 26 下一页
摘要: View Code //**************************************************Description 问题的提出:约19世纪末,在欧州的商店中出售一种智力玩具,在一块铜板上有三根杆(分别使A、B、C),最左边的杆上自上而下、由小到大顺序串着由64个圆盘构成的塔。目的是将最左边杆上的盘全部移到右边的杆上,条件是一次只能移动一个盘,且不允许大盘放在小盘的上面。这是一个著名的问题,几乎所有的教材上都有这个问题。由于条件是一次只能移动一个盘,且不允许大盘放在小盘上面,所以64个盘的移动次数是:18446744073709551615 这是一个天文数字,若每 阅读全文
posted @ 2011-04-13 15:06 聊聊IT那些事 阅读(506) 评论(0) 推荐(0)
摘要: lcs#include"iostream"using namespace std;int c[1001][1001];int Max(int a, int b){ return a>b?a:b;}void LCS(char aa[], char bb[], int x, int y){ int i,j; for(i=0;i<=x;i++) c[i][0]=0; for(j=0;j<=y;j++) c[0][j]=0; for(i=1;i<=x;i++) { for(j=1;j<=y;j++) { if(aa[i-1]==bb[j-1]) {c[ 阅读全文
posted @ 2011-04-12 18:16 聊聊IT那些事 阅读(262) 评论(2) 推荐(0)
摘要: View Code #include"iostream"using namespace std;int main(){ int t; int n,a; int i,j=0,k; cin>>t; while(t--) { cin>>n; int sum=0,Max=-99999999; int start=0,end=0; k=0; for(i=0;i<n;i++) { cin>>a; sum+=a; if(sum>Max) { Max=sum; start=k+1; end=i+1; } if(sum<0) { sum= 阅读全文
posted @ 2011-04-12 14:20 聊聊IT那些事 阅读(320) 评论(0) 推荐(0)
摘要: 单词倒置Time Limit:1000MS Memory Limit:65536KTotal Submit:68 Accepted:8 Description 请编制程序实现下面的功能:将一篇英文文章中的以空格或标点符号为分隔的所有单词进行倒排,同时去除标点符号,之后输出已处理的英语文章(应不含标点符号)。Input 有多组数据,每组一行,每组就是一篇小文章。每篇小文章都由大写字母、小写字母、空格及标点符号组成,遇到#时表示输入结束。Output 每组输出其对应的字符串,其单独成行。Sample Input You He MeI am a student.#Sample Output Me H 阅读全文
posted @ 2011-04-11 18:25 聊聊IT那些事 阅读(414) 评论(0) 推荐(0)
摘要: View Code void get_next(){ int i=-1,j=0; next[0]=-1; while(j<m-1) { if(i==-1||b[i]==b[j]) { ++i; ++j; next[j]=i;} else i=next[i]; }}int Index_KMP(){ int i=0,j=0; while(i<n && j<m) { if(a[i]==b[j]||j==-1) { ++i; ++j;} else j=next[j]; } if(j>=m) return i-m+1; else return -1;}代码:Vie 阅读全文
posted @ 2011-04-08 09:51 聊聊IT那些事 阅读(320) 评论(0) 推荐(0)
摘要: View Code #include"iostream"using namespace std;int main(){ int n; int a,b,c; int sum; int i,j; cin>>n; while(n--) { cin>>a>>b>>c; if(b>=c) cout<<"Yes"<<endl; else { if(a==0) cout<<"No"<<endl; else if(a>0&&a& 阅读全文
posted @ 2011-04-07 17:31 聊聊IT那些事 阅读(262) 评论(0) 推荐(0)
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1256View Code #include"iostream"using namespace std;int n,m;int i,j;char a[10];int y; int d; // d表示行的宽度void fun1(){ for( i=0;i<d-y;i++) { if(i<m/6+1) printf(" "); else printf("%s",a); } printf("\n");}void fun2(in 阅读全文
posted @ 2011-04-07 17:07 聊聊IT那些事 阅读(392) 评论(0) 推荐(0)
摘要: 枚举法。。。。View Code #include"iostream"#define M 1000001using namespace std;int a[M];int main(){ int m,n; int i; memset(a,0,sizeof(a)); for(i=1;i<=1000001;i++) { int x=i; int k=i; while(x) { if(x%10==4||x%100==62){ a[k]=1; } x/=10; } } while(cin>>m>>n,m+n) { int flag=0; for(i=m; 阅读全文
posted @ 2011-04-07 16:00 聊聊IT那些事 阅读(295) 评论(0) 推荐(0)
摘要: 产生冠军的条件:(1)获胜的人没输过一次(2)最终获胜的人只有一个View Code #include"iostream"//#include"algorithm"using namespace std;#define M 1010int main(){ int n; int i,j; char a[M][100],b[M][100]; int sum[M],c[M]; while(cin>>n,n) { memset(sum,0,sizeof(sum)); //0表示失败 for(i=0;i<n;i++) { cin>>a 阅读全文
posted @ 2011-04-07 09:34 聊聊IT那些事 阅读(650) 评论(0) 推荐(0)
摘要: 借鉴了一位dn的,筛选法。求出每个数的因子和,然后看因子和是否在1000以内,是的话就证明等于因子和的这个数是不可摸数。http://acm.hdu.edu.cn/showproblem.php?pid=1999 阅读全文
posted @ 2011-04-06 21:13 聊聊IT那些事 阅读(309) 评论(0) 推荐(0)
上一页 1 ··· 12 13 14 15 16 17 18 19 20 ··· 26 下一页