上一页 1 ··· 9 10 11 12 13 14 15 16 17 ··· 30 下一页
  2012年9月22日
摘要: 字符串处理。CODE:#include<iostream>#include<cstdlib>#include<cstdio>#include<ctype.h>#include<cstring>usingnamespacestd;charss[27]="A3HILJMO2TUVWXY5";charsd[10]="1SEZ8";intcheck1(char*str){intlen=strlen(str);for(inti=0;i<=len/2;i++){if(str[i]!=str[len-i 阅读全文
posted @ 2012-09-22 16:35 有间博客 阅读(238) 评论(0) 推荐(0) 编辑
  2012年9月20日
摘要: 题意:Harry上变形课,如果咒语是以a开头b结尾的一个单词,那么它的作用就恰好是使A物体变成B物体。给你一张单词表,问你能否将B(Ball)转换为M(Mouse)。思路:以单词词头,词尾为顶点建图,通过Floyd判断是否连通就行。CODE:#include<iostream>#include<cstdio>#include<cstdlib>usingnamespacestd;constintM=1001;intG[M][M];voidFloyd(){for(intk='a';k<='z';k++)for(inti=&# 阅读全文
posted @ 2012-09-20 21:38 有间博客 阅读(202) 评论(0) 推荐(0) 编辑
摘要: 大意:现在给定房间的结构,箱子的位置,搬运工的位置和箱子要被推去的位置,请你计算出搬运工至少要推动箱子多少格。(搬运工只能推箱子而不能拉箱子,因此如果箱子被推到一个角上(如图)那么箱子就不能再被移动了,如果箱子被推到一面墙上,那么箱子只能沿着墙移动。)思路:很简单的状态搜索题,大概就是对箱子采用BFS的思想,然后判断人是否可以走到箱子的对面(DFS/BFS),由于数据大,可以用四重标记数组来标记(hash[M][M][M][M])不过有许多细节需要注意。(1)采用DFS/BFS判断人是否可以到达箱子的对面时,要明确人不能穿过箱子,即对箱子标记flag[p.Bx][p.By] = 1;(2)求箱 阅读全文
posted @ 2012-09-20 19:23 有间博客 阅读(1180) 评论(0) 推荐(0) 编辑
摘要: 大意:给你一定的关系,如A<B,B<C,啥的,让你排序。思路:比较明显的拓扑排序,只不过是每输入一组数据就排序一次。(1)如果输入之后发现有环的话,立马终止。(2)如果序列不确定,则说明存在多组入度为0的顶点。q.size() > 1(3)顺序确定。 阅读全文
posted @ 2012-09-20 11:05 有间博客 阅读(106) 评论(0) 推荐(0) 编辑
  2012年9月18日
摘要: 大意:Dandelion's uncle的工厂开始分红,厂里的工人们有些有特殊的要求,如A工人的工资一定要大于B,B工人的工资一定要大于C,而不能出现A > B,B> C,C > A的情况。思路:拓扑排序。(基于邻接表BFS拓扑排序,邻接矩阵会MLE)。CODE:#include<iostream>#include<cstdio>#include<cstdlib>#include<queue>usingnamespacestd;constintM=10005;intu[4*M],v[4*M],next[4*M],w[4* 阅读全文
posted @ 2012-09-18 21:25 有间博客 阅读(261) 评论(0) 推荐(0) 编辑
摘要: 大意:拓扑排序或者Floyd判断是否有环。基于邻接表的BFS实现的拓扑排序。CODE1:#include<iostream>#include<queue>usingnamespacestd;#defineM10005structedge{intv,w,next;}edge[20005];intind[M],first[M],cnt,n,m,tot,num;inttopo[M];voidinit(){cnt=0;tot=0;memset(first,-1,sizeof(first));memset(ind,0,sizeof(ind));memset(topo,0,size 阅读全文
posted @ 2012-09-18 20:31 有间博客 阅读(323) 评论(0) 推荐(0) 编辑
摘要: 最近做图的题比较多,除了克鲁斯卡尔和floyd,像广搜,普里姆,Bellman-Ford,迪杰斯特拉,SPFA,拓扑排序等等,都用到图的邻接表形式。数据结构书上表示邻接表比较复杂,一般形式如下:typedefstructNode{intdest;//邻接边的弧头结点序号intweight;//权值信息structNode*next;//指向下一条邻接边}Edge;//单链表结点的结构体typedefstruct{DataTypedata;//结点的一些数据,比如名字intsorce;//邻接边的弧尾结点序号Edge*adj;//邻接边头指针}AdjHeight;//数组的数据元素类型的结构体t 阅读全文
posted @ 2012-09-18 16:50 有间博客 阅读(10066) 评论(1) 推荐(1) 编辑
摘要: STL map + 拓扑排序。#include<iostream>#include<cstdio>#include<cstdlib>#include<map>usingnamespacestd;constintSIZE=5000;intind[SIZE];intcnt;map<string,int>Map;voidinit(){Map.clear();memset(ind,0,sizeof(ind));cnt=0;}intmain(){intn;charsz1[31],sz2[31];while(~scanf("%d&quo 阅读全文
posted @ 2012-09-18 14:41 有间博客 阅读(128) 评论(0) 推荐(0) 编辑
摘要: 大意:判断是否有向图是否有环。思路1:通过Floyd传递闭包来确定是否有向环。(350MS)思路2:通过拓扑排序判断是否存在有向环。(109MS)CODE1:#include<iostream>#include<cstdio>#include<cstdlib>usingnamespacestd;constintSIZE=510;intG[SIZE][SIZE];intn,m;intFLoyd(){for(intk=0;k<n;k++)for(inti=0;i<n;i++)for(intj=0;j<n;j++)G[i][j]=G[i][j]| 阅读全文
posted @ 2012-09-18 11:18 有间博客 阅读(172) 评论(0) 推荐(0) 编辑
  2012年9月17日
摘要: 拓扑排序。CODE:#include<iostream>usingnamespacestd;constintSIZE=510;inttopo[SIZE],ind[SIZE];intG[SIZE][SIZE];intn,m;inttoposort(){for(inti=1;i<=n;i++){intu;for(u=1;u<=n;u++)if(!ind[u])break;if(u>n)return0;topo[i]=u;ind[u]--;for(intv=1;v<=n;v++)if(G[u][v])ind[v]--;}return1;}voidinit(){me 阅读全文
posted @ 2012-09-17 22:15 有间博客 阅读(190) 评论(0) 推荐(0) 编辑
上一页 1 ··· 9 10 11 12 13 14 15 16 17 ··· 30 下一页