2011年7月16日

sicily 1282. Computer Game

摘要: // 题意: A是主串,B是子串,都由数字组成, 查询B串在A串第一次出现的位置,若找不到则输出no solution// 注意子串的最大长度是60000,但主串的长度未知,所以要开大些#include <iostream> //KMP算法#include<stdio.h>using namespace std;int A[1000000],B[80000]; //A是主串,B是子串,查询B串在A串的哪些地方出现int n,m,next[80000]; //n,m分别是A,B的串长度,A,B的下标是从1开始的void get_next(){ next[1... 阅读全文

posted @ 2011-07-16 21:34 sysu_mjc 阅读(710) 评论(2) 推荐(0) 编辑

sicily 1823. Hardest Job Ever!

摘要: #include <iostream> //求顶点1到n的最短距离,Dijkstra算法#include<stdio.h>using namespace std;#define Max 210#define MaxW 20000int n,m,edge[Max][Max],S[Max],distD[Max];void Dijkstra(int v) { for(int i=0;i<n;++i) { distD[i]=edge[v][i]; S[i]=0; } S[v]=1; for(int i=1;i<n;++i) { int min=MaxW,u=0; f 阅读全文

posted @ 2011-07-16 21:06 sysu_mjc 阅读(206) 评论(0) 推荐(0) 编辑

sicily 1350. Piggy banks

摘要: #include<iostream> //给出每个点入度为1的有向图,求环的个数#include<stdio.h>using namespace std;#define M 1000005int par[M],vis[M],path[M],circle[M];int main(){ int n; while(scanf("%d",&n)!=EOF) { for(int i=1;i<=n;++i) scanf("%d",&par[i]); for(int i=1;i<=n;++i) { vis[i]=0; 阅读全文

posted @ 2011-07-16 20:36 sysu_mjc 阅读(221) 评论(0) 推荐(0) 编辑

sicily 1166. Computer Transformat

摘要: #include<iostream> //DP+高精度#include <string>using namespace std;int compare(string str1, string str2){ while(!str1.empty()&&str1[0]=='0') { str1.erase(0,1); } while(!str2.empty()&&str2[0]=='0') { str2.erase(0,1); } if(str1.size() > str2.size()) //长度长的整数 阅读全文

posted @ 2011-07-16 15:08 sysu_mjc 阅读(210) 评论(0) 推荐(0) 编辑

sicily 1197. Hotel

摘要: // 题意:给出一个元字符串goal,里面含有特别字符*和?,其中*代表任意多个字符,?代表一个字符,// 有n个字符串str,问哪些字符串与元字符串相匹配#include<iostream> //含通用符的字符串的最长匹配#include<stdio.h>#include<cstring>using namespace std;char goal[60],str[60];int f[60][60]; //f[i][j]=1,表示一个字符串的0-i子串与另一个字符串的0-j子串匹配,f[i][j]=0则是不匹配int dp(int i,int j) /... 阅读全文

posted @ 2011-07-16 11:08 sysu_mjc 阅读(208) 评论(0) 推荐(0) 编辑

导航