上一页 1 ··· 7 8 9 10 11 12 13 14 15 ··· 26 下一页
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2087View Code #include<iostream>using namespace std;int main(){ char a[1001],b[1001]; int i,j; while(cin>>a) { if(a[0]=='#') break; cin>>b; int L1=strlen(a); int L2=strlen(b); int sign=0 , flag=0; i=sign,j=0; while(i<L1) { if(a[i 阅读全文
posted @ 2011-05-16 21:04 聊聊IT那些事 阅读(505) 评论(0) 推荐(0) 编辑
摘要: View Code /*Poj2406题解:if(len%(len-next[len])==0),则重复子串的长度为 len-next[len].证明如下,next[len]表示到len为止,满足既是前缀子串又是后缀子串的最长长度,如下图{a,c} = {b,d}若len%(len – next[len])==0,则说明{ a ,b} 的长度可以被{a, d} 的长度整除,同样可以被{b,c}的长度整除。而此时,由于{b,c}是{b,d}的前缀子串又是后缀子串且保持{a,b}的长度可以被{a,c}整除。这样,{a,c}就相当于原来的{a,d},而{b,c}就相当于原来的{b,d},通过这样的划 阅读全文
posted @ 2011-05-16 20:10 聊聊IT那些事 阅读(639) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=2752View Code //寻找前子串与后子串相等的子串#include<iostream>using namespace std;char ch[400001];int next[400001];int ans[400001];void solve (char *s, int ls){ int i=0,j=-1; next[0] = -1; while(i<ls) { if(j==-1 || s[i]==s[j]) { i++; j++; next[i] = j; } else { j = next[j]; } }}i 阅读全文
posted @ 2011-05-16 20:08 聊聊IT那些事 阅读(188) 评论(0) 推荐(0) 编辑
摘要: 字符串查找Time Limit:1000MS Memory Limit:65536KTotal Submit:73 Accepted:24 Description 请编制程序实现下面的功能:统计一个子字符串在另一个字符串中出现的次数。Input 有多组数据,每组两行,两行输入的都是字符串。 字符串中字符没有限制,如第一行第一个字符是#时表示输入结束。Output 每组只输出一个整数,其单独成行,该整数代表第二个字符串在第一个字符串中出现的次数。Sample Input asd asasdfg asd as zx67 asd mkloas#Sample Output 6Hint 输入数据的格式是 阅读全文
posted @ 2011-05-15 20:54 聊聊IT那些事 阅读(289) 评论(0) 推荐(0) 编辑
摘要: 连通图Time Limit:1000MS Memory Limit:65536KTotal Submit:17 Accepted:4 Description Input 输入:每组数据的第一行是两个整数n 和m(0 < n <=100)。n 表示图的顶点 数目,0 < m <= 100 表示图中边的数目。如果n 为 0 表示输入结束。随后有m 行数据,每 行有两个值x 和y(0 < x , y <=n ),表示顶点x 和y 相连,顶点的编号从1 开始计 算。输入不保证这些边是否重复。 Output 输出:对于每组输入数据,如果所有从1~n所有顶点都是连通的, 阅读全文
posted @ 2011-05-15 19:41 聊聊IT那些事 阅读(812) 评论(0) 推荐(0) 编辑
摘要: 都是基础知识!http://acm.hdu.edu.cn/showproblem.php?pid=2057看了一位dn的解释,借鉴了:http://hi.baidu.com/gminking/blog/item/691ee158d213754dfbf2c016.html/cmtid/881e0f308ee322345bb5f5a4题目求的是十六进制的加法。刚开始想的是把十六进制转化为十进制,进行加法运算后,再转化为十六进制。后来发现自己忘了C中存在十六进制的输入输出(%X,%x)。所以这题可以直接用十六进制输入,然后进行十六进制的运算(其实不管是什么进制,在计算机中都是以二进制来计算的,只是按 阅读全文
posted @ 2011-05-13 21:05 聊聊IT那些事 阅读(1200) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=3790View Code #include<iostream>#define M 1001#define Max 0x7fffffffusing namespace std;int n,m;int a,b,d,p;int s,t;int map[M][M];int cost[M][M];int de[M];int co[M];int visit[M];int len;int _min;void Init(){ int i,j; for(i=0;i<=n;i++) { for(j=0;j< 阅读全文
posted @ 2011-05-13 19:46 聊聊IT那些事 阅读(645) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/vcontest/vtl/problem/showproblem/vtlid/1816/problemid/1005View Code #include"iostream"using namespace std;int main(){ int t; int n,i; int x[101],y[101]; cin>>t; while(t--) { double sum=0; cin>>n; for(i=0;i<n;i++) cin>>x[i]>>y[i]; for(i=1;i&l 阅读全文
posted @ 2011-05-11 21:48 聊聊IT那些事 阅读(287) 评论(0) 推荐(0) 编辑
摘要: View Code #include"iostream"using namespace std;int k=0;void hanoi(int m , char a ,char b, char c){ if(m==1) { k++; printf("%c->%c ",a , c); return; } hanoi(m-1, a, c , b); printf("%c->%c ",a , c); k++; hanoi(m-1 , b, a, c);}int main(){ int n; char x,y,z; while(ci 阅读全文
posted @ 2011-05-10 20:25 聊聊IT那些事 阅读(166) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2553Nqueen问题#include"iostream"using namespace std;int n;int a[20];int b[20];int c;bool Panduan(int x){ for(int i=0; i<x; i++) { if( (a[x]-a[i])==0 || (abs(a[x]-a[i])-abs(x-i))==0 ) return false; //关键点 } return true;}void dfs(int y ,int z){ for(i 阅读全文
posted @ 2011-05-10 20:05 聊聊IT那些事 阅读(422) 评论(0) 推荐(0) 编辑
上一页 1 ··· 7 8 9 10 11 12 13 14 15 ··· 26 下一页