- 博客(11)
- 收藏
- 关注
原创 HDU 1043 eight 八数码
其实最重要的就是判重这个关卡,说到底用的也是一个哈希的算法,利用当前这个数的逆序数来构建的。//ashione 2011-3-31 #include #include #include using namespace std; #define N 10 #define MAX 362881 //最多可能有9!个排列 int fac[]={1,1,2,6,24,120,720,5040,40320,362880};//康托展开数列 bool visited[MAX]; string rou
2011-05-26 14:08:00 1929 1
原创 HDU 1856 并查集
[code]#include#includeusingnamespacestd;#define M 1000001intnum[M],rote[M],Maxstep;voidinit(intMax){for(inti=0;i=num[b]){num[a]+=num[b];rote[b]=rote[a];Maxstep=Maxstep>num[a]?Maxstep:num[a];}else{num[b]+=num[a];rote[a]=rote[b];Maxstep=Maxstep>num[b]?Maxste
2011-05-25 15:49:00 550
原创 HDU 1879 继续畅通工程(最小生成树 Kruskal算法)
#include #include #include using namespace std; #define M 101 typedef struct egde{ int e,s,weight; bool build; }egde; egde info[M*M/2]; int c[M],n,num; bool cmp(const egde a,const egde b){ if(a.build!=b.build) return a.build
2011-05-31 20:13:00 985
原创 HDU 1863 畅通工程(最小生成树prim算法)
#include #include #include using namespace std; #define M 101 int map[M][M],v,arc; void init(){ //用-1标记距离为无穷大。 memset(map,-1,sizeof(map)); int from,to,weight; while(arc--){ cin>>from>>to>>weight; if(map[from][to]weight) map[from][t
2011-05-31 17:25:00 660
原创 HDU 2222 keyword search(AC自动机)
#include #include #include using namespace std; #define M 1000001 #define N 26 char s[M],word[2*N]; typedef struct link{ link *next[N],*fail; int cn; link(){ memset(next,NULL,sizeof(next)); fail=NULL,cn=0; } }tire; link *q[M]; void
2011-05-29 18:08:00 573
原创 HDU 1358 Period (KMP)
<br />#include<iostream> #include<cstring> using namespace std; #define M 1000001 int next[M],len,n; char s[M],t[M]; void getnext(){ int i=1,j=0; next[i]=0; for(i=2;i<=len;i++){ while(j>0 && s[j+1]!=s[i]) j=next[j]; if(s[j+1]==s[i])
2011-05-28 22:53:00 544
原创 HDU 2152 Fruit 母函数
<br />最基础的母函数,0ms秒过。<br />直接模版过掉。<br />#include<iostream> #include<cstring> using namespace std; #define M 101 int main(){ int n,m; while(cin>>n>>m){ int least[M],most[M],c1[M]={1},c2[M]={0},i,j,k; for(i=0;i<n;i++) cin>>least[i]>>most[i];
2011-05-27 12:12:00 604
原创 HDU 2082 找单词
<br />总得来说就是一道水题,只不过可以包括很多关于基础母函数的概念<br />#include<iostream> #include<cstring> using namespace std; #define M 51 int main(){ int t; cin>>t; while(t--){ int charnum[27]={0},i,j,k,c1[M]={1},c2[M]={0},count; //c1[0]=1,可以说是母函数求值的一个入口,后面的步骤全部是从这里出
2011-05-26 22:46:00 859
原创 HDU 1273 小希的迷宫
<br />刚开始我天真的以为是用图论做的,最后一直MLE我就很蛋疼,我说用MAP和string 映射怎么他妈就要错呢。。。真的倒塌,自己还是菜菜呀,认真学习中。。。<br />// by ashione 用<set>一直TLE 可能STL速度很慢吧,换成flag标记就好了。 #include<iostream> #include<cstdio> #include<set> using namespace std; #define M 100001 int root[M+1]; bool ma
2011-05-26 20:50:00 651
原创 HDU 1711 Number Sequence (kmp)
//ashione 2011-5 -26 //有时间再把解析写上去,其实自己也是一知半解 #include #include using namespace std; #define Maxsize 10001 int t,sn,tn,nums[Maxsize/100*Maxsize],numt[Maxsize],next[Maxsize/100*Maxsize]; void Getnext(){ int i=1,j=0; next[i]=0;
2011-05-26 18:23:00 618
原创 ZOJ 1005 Jugs
#include #include #include #include #include #include using namespace std; string markway[2][5]={{"fill A","empty A","pour A B"}, {"fill B","empty B","pour B A"}}; #define M 1001 bool jugs[M][M]; int n,m,d; typedef struct p
2011-05-25 18:26:00 1757 1
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人