摘要: 1 递归形式 2 3 int find(int x) 4 { 5 if(x!=f[x])f[x]=find(f[x]); 6 return f[x]; 7 } 8 9 10 非递归11 int find(int x)12 {13 if(f[x]==x)return x;14 int r=x;15 while(r!=f[r])16 {17 r=f[r];18 }19 int y=x,k;20 while(y!=f[y])21 {22 23 k=f[y];24 f[y... 阅读全文
posted @ 2012-03-15 21:08 Szz 阅读(181) 评论(0) 推荐(0) 编辑
摘要: #include<stdio.h>int f[30005];int find(int x){ if(x!=f[x])f[x]=find(f[x]); return f[x];}int main(){ int n,m,i,j,k,a,b; while(scanf("%d%d",&n,&m),m+n) { for(i=0;i<=n;i++)f[i]=i; for(i=1;i<=m;i++) { scanf("%d",&k); scanf("%d",&a); in... 阅读全文
posted @ 2012-03-15 20:59 Szz 阅读(141) 评论(0) 推荐(0) 编辑
摘要: 1 strstr(a,b); 2 返回b串在a串中出现的第一个位置,否则返回NULL 3 4 5 #include<string.h> 6 #include<stdio.h> 7 const int N=100; 8 int m; 9 char dna[N][N];10 int search(char s[],int len)11 {12 int i;13 for(i=1;i<m;i++)14 {15 if(!strstr(dna[i],s))return 0;16 }17 return 1;18 }19 int main()20 ... 阅读全文
posted @ 2012-03-15 20:29 Szz 阅读(190) 评论(0) 推荐(0) 编辑
摘要: 1 void get_next(char *str) 2 { 3 int len=strlen(str); 4 next[0]=-1; 5 int j=0,k=-1;//k记录next[]; 6 7 while(j<len) 8 { 9 if(k==-1||str[j]==str[k])10 {11 k++;12 j++;13 if(str[k]!=str[j])14 next[j]=k;15 ... 阅读全文
posted @ 2012-03-15 20:08 Szz 阅读(171) 评论(0) 推荐(0) 编辑
摘要: poj 3080 PKU 3080 Blue Jeans(kmp)?#include<stdio.h>#include<string.h>const int N=100;int n,m,next[N];char dna[N][N];void get_next(char *str,int len){ next[0]=-1; int j=0,k=-1;//k记录next[]; while(j<len) { if(k==-1||str[j]==str[k]) { k++; j++; ... 阅读全文
posted @ 2012-03-15 20:04 Szz 阅读(176) 评论(0) 推荐(0) 编辑
摘要: #include<stdio.h>#include<string.h>const int N=100;int n,m,next[N];char dna[N][N];void get_next(char *str,int len){ next[0]=-1; int j=0,k=-1;//k记录next[]; while(j<len) { if(k==-1||str[j]==str[k]) { k++; j++; if(str[k]!=str[j]) ... 阅读全文
posted @ 2012-03-15 20:02 Szz 阅读(158) 评论(0) 推荐(0) 编辑
摘要: PKU 3370 Halloween treats 【鸽笼定理】分类: 数论 2010-08-20 19:21 127人阅读 评论(0) 收藏 举报【题目地址】http://acm.pku.edu.cn/JudgeOnline/problem?id=3370【题目大意】 万圣节邻居i会发给孩子们一定数量的糖果a[i],现在有c个孩子和n户邻居(1<=c<=n<=100000), 为了不引起纠纷,孩子们决定选择性的去某些邻居家索要糖果,使得到的糖果总数可以均分给n个人(只要均分就行,不要求糖果数最多)。【解题思路】 基本原理:如果n+1个物体放进n个盒子,那么至少有一个盒子包含 阅读全文
posted @ 2012-03-14 17:46 Szz 阅读(411) 评论(0) 推荐(0) 编辑
摘要: Annoying painting toolTime Limit: 1000MS Memory limit: 65536K题目描述Maybe you wonder what an annoying painting tool is? First of all, the painting tool we speak of supports only black and white. Therefore, a picture consists of a rectangular area of pixels, which are either black or white. Second, ther 阅读全文
posted @ 2012-03-12 21:00 Szz 阅读(208) 评论(0) 推荐(0) 编辑
摘要: 找差异为一个字符的串http://poj.org/problem?id=1035#include<iostream>#include<string>#include<string.h>#include<stdlib.h>#include<stdio.h>#define N 10005using namespace std;string str[N];int num,l,b[N];int replace(string c,string b){ int i,sum=0; for(i=0;i<c.length();i++) { if( 阅读全文
posted @ 2012-03-09 21:55 Szz 阅读(161) 评论(0) 推荐(0) 编辑
摘要: #include<iostream>#include<stdio.h>#define N 201#include<vector>#include<string.h>using namespace std;vector<int>g[N];int result[N],vis[N],n,m;int dfs(int x){ int i,j; for(j=0;j<g[x].size();j++) { i=g[x][j]; if(!vis[i]) { vis[i]=1; if(result[i]==0|... 阅读全文
posted @ 2012-03-08 20:35 Szz 阅读(160) 评论(0) 推荐(0) 编辑