上一页 1 ··· 11 12 13 14 15 16 17 18 19 ··· 36 下一页

2011年5月19日

poj 2752

摘要: 题意:给你一个串,如果这个串存在一个长度为n的前缀串,和长度为n的后缀串,并且这两个串相等,则输出他们的长度n。求出所有的长度n。代码:#include<iostream>#include<fstream>using namespace std;char c[400003];int next[400004];int len;void getnext(){ int i,j,k; j=0;k=-1; next[0]=-1; while(j<len) { if(k==-1||c[j]==c[k]) next[++j]=++k; else k=next[k]; }}voi 阅读全文

posted @ 2011-05-19 16:39 宇宙吾心 阅读(312) 评论(0) 推荐(0)

poj 3461

摘要: 题意:给你一个子串(模式串)和一个母串(文本),问子串在母串中出现的次数。代码:#include<iostream>#include<fstream>using namespace std;char s[10012];char t[1000012];int next[10011];void getnext(){ int i,j,k; j=0;k=-1;next[0]=-1; int len=strlen(s); while(j<len) if(k==-1||s[k]==s[j]) next[++j]=++k; else k=next[k];}void kmp(){ 阅读全文

posted @ 2011-05-19 16:23 宇宙吾心 阅读(419) 评论(0) 推荐(0)

poj 3450

摘要: 题意:给你n个的串,求出它们的最长公共子串,如果不存在这个子串,则输出“IDENTITYLOST”,如果存在多个最长公共子串,则输出字典序最小的那一个。代码:#include<iostream>#include<fstream>using namespace std;char c[4001][202];int len[4001];int next[210];char str[210];int n;void getnext(char c[]){ int i,j,k; int len=strlen(c); j=0;k=-1;next[0]=-1; while(j<le 阅读全文

posted @ 2011-05-19 16:04 宇宙吾心 阅读(442) 评论(0) 推荐(0)

2011年5月18日

poj 1655

摘要: 题意:一棵树,定义每个节点的balance值:去掉这点节点后的森林里所有树的最大节点数。求出最小的balance值和其所对应的节点编号。代码:#include<iostream>#include<fstream>using namespace std;struct e{ int data; e *next;};e edge[20001];int v[20001];int a[20001];int b[20001];int n;void solve(int s){ int i,j=0,k=0; e *p=edge[s].next; v[s]=1; while(p){ if 阅读全文

posted @ 2011-05-18 21:20 宇宙吾心 阅读(399) 评论(0) 推荐(0)

poj 3264

摘要: rmq代码:#include<iostream>#include<fstream>#include<cmath>using namespace std;int n,m;int dp[50001][20];int b[50001][20];int a[50001];void read(){// ifstream cin("in.txt"); int i,j,k,s,t; cin>>n>>m; for(i=1;i<=n;i++) // cin>>a[i]; scanf("%d",& 阅读全文

posted @ 2011-05-18 20:11 宇宙吾心 阅读(351) 评论(0) 推荐(0)

poj 2195

摘要: 题意:一个row*col的矩阵,m表示人,H表示房子,.表示空地,人数和房子数相等,如下图:5 5HH..m...............mm..H现在要让所有的人都进入不同的房子内,问总共最少走多少步?代码:#include<iostream>#include<fstream>#include<queue>#include<cmath>using namespace std;int n,m;struct e{ int data; int c,f,w; e *next; e *op;};e edge[400];int x[101],y[101], 阅读全文

posted @ 2011-05-18 17:50 宇宙吾心 阅读(999) 评论(0) 推荐(0)

poj 1087

摘要: 题意:有n个不同的插座,有m台不同的机器需要m种插头,有k组转换:插头A能由插头B转换而来。问这些机器最少有几台不能插上插座。代码:#include<iostream>#include<fstream>#include<queue>using namespace std;struct e{ int data; e *next; int c,f; e *op;};e edge[500];int d[500];int start,end;int n,m;int build(){ int i,j,k; queue<int> q; memset(d,0, 阅读全文

posted @ 2011-05-18 16:30 宇宙吾心 阅读(888) 评论(0) 推荐(0)

2011年5月17日

poj 3352

摘要: 题意:一个连通的无向图,求至少需要添加几条边,救能保证删除任意一条边,图仍然是连通的。思路:边的双连通图。其实就是要求至少添加几条边,可以使整个图成为一个边双连通图。用tarjan算法(求割点割边)求出low数组,这里可以简化,然后依据“low相同的点在一个边连通分量中”,缩点之后构造成树(这里可以直接利用low[]数组,low[i]即为第i节点所在的连通分量的标号)。求出树中出度为1的节点数left,答案即为(leaf+1)/2。代码:#include<iostream>#include<fstream>using namespace std;int n,m;stru 阅读全文

posted @ 2011-05-17 19:28 宇宙吾心 阅读(972) 评论(0) 推荐(0)

poj 2117

摘要: 题意:一个无向图,现在要去掉其中一个点,要求去掉这个点之后,总连通分支数最大。思路:割点,连通分量。主要分三种情况:1、最普通的情况:如果有边,而且存在割点,就是tarjon算法的深搜过程中求出所有割点的子树的个数(其实也就是如果去掉割点,能使连通分支数增加的个数)的最大值,再加上原来的强连通分支数即可。2、最容易出错的情况:如果没有边,则应该去掉一个点后,连通分支数为原顶点数减去1。3、如果有边,但是图中不存在割点,则输出原来图中连通分支数就行了。代码:#include<iostream>#include<fstream>using namespace std;int 阅读全文

posted @ 2011-05-17 18:54 宇宙吾心 阅读(666) 评论(0) 推荐(0)

poj 2560

摘要: 题意:有n个点,并且知道它们的坐标,求连接所有点的最短路径。代码:#include<iostream>#include<fstream>#include<cmath>using namespace std;double x[101],y[101];double d[101];double w[101][101];int v[101];int n;void read(){// ifstream cin("in.txt"); int i,j,k; cin>>n; for(i=1;i<=n;i++) cin>>x[ 阅读全文

posted @ 2011-05-17 16:17 宇宙吾心 阅读(413) 评论(0) 推荐(0)

上一页 1 ··· 11 12 13 14 15 16 17 18 19 ··· 36 下一页

导航