摘要: http://poj.org/problem?id=1094题意相当的坑爹,才开始我的步骤是:1 判断是否有环,如果存在环,就输出Inconsistency found after 2 relations.不能确定该序列大小2 如果不存在环,然后判断是否能够判断出唯一的该序列,每次去入读为0的点时,一定会有一个,而且最终取完。。。3 然后判断。可是Discuss里面的数据就是不过。。。于是看了看讨论。原来,只要在出现环之前,能够判断出该序列的顺序就输出顺序,后面的就只输入不处理了(不管了)。。。还有判断环的优先级要高于序列唯一性判断的优先级。。。这样的话要每输入一条边,就要进行一次拓扑排序,然 阅读全文
posted @ 2012-03-11 17:29 E_star 阅读(260) 评论(0) 推荐(0)
摘要: http://poj.org/problem?id=1789很裸的一道最小生成树题目,就是建立map[][]后直接套模板。。。。http://poj.org/problem?id=2485求最小生成树中的最大权值。。。做这个题时犯了个很2的错误,贡献了好几次WA。。最后重敲了一遍A了。。不说那2的错误了。http://poj.org/problem?id=1258裸的最小生成树http://poj.org/problem?id=3026注意这里the group may split in two or more groups 应为他在最小生成树专题里,看看题目就可以理解转换成最小生成树求解。如 阅读全文
posted @ 2012-03-10 10:31 E_star 阅读(339) 评论(0) 推荐(0)
摘要: http://poj.org/problem?id=2240刚开始看到题目时,看到数据量很小,就想到了搜索,搜索所有的环然后将边的权值相乘看是否大存在于1.0的环。。结果果断的TLE无语。。。最后看了看Discuss floyd1AView Code #include <iostream>#include <cstring>#include <cstdio>#include <cmath>#define maxn 34#define eps 1e-8using namespace std;char str[maxn][maxn];double m 阅读全文
posted @ 2012-03-09 19:34 E_star 阅读(209) 评论(0) 推荐(0)
摘要: http://poj.org/problem?id=1125刚开始以为是求最小生成树,可是打完代码一看结果根本不对。最后看了一下discuss原来是的那个一个点和m个点连接时,可以同时传送信息。所以只要转换成dijkstra求原点到所有点的最短然后找出最大时间,就是从原点到最后一个点的时间长度了,,循环遍历所有点当做原点情况,然后找出最佳值。。View Code #include <iostream>#include <cstring>#include <cstdio>#include <cmath>#define maxn 107using n 阅读全文
posted @ 2012-03-08 21:29 E_star 阅读(213) 评论(0) 推荐(0)
摘要: http://poj.org/problem?id=2253这道题的提议就是就最小生成树中的最大权所以我用了最小生成树prim算法View Code #include <iostream>#include <cstring>#include <cstdio>#include <cmath>#define maxn 207using namespace std;const double inf = 99999999.0;bool vt[maxn];double dis[maxn],map[maxn][maxn];struct node{ doubl 阅读全文
posted @ 2012-03-08 00:09 E_star 阅读(248) 评论(0) 推荐(0)
摘要: http://poj.org/problem?id=1062这道题太让我纠结了。。才开始把提议理解错了,就是那个等级问题,我以为只要交易的双方的等级差异<=m就可以呢。结果样例过了无限的wa最后搜了一下解题报告才看懂个那个等级问题。他是交易的所有人的等级差异都要<=m才是满足条件的。。。唉。。枚举所有可能参与交易的对象+Dijkstra求最短路就可以了。。。可是在这里我就卡死了。。。有个问题使我不解也讨论了很久还是没发现。。代码中见。。求解View Code #include <iostream>#include <cstring>#include < 阅读全文
posted @ 2012-03-07 22:00 E_star 阅读(286) 评论(0) 推荐(0)
摘要: Dijkstra 求单源最短路径,无法处理代负权的边。时间复杂度O(n^2)http://www.wutianqi.com/?p=1890Bellman_Ford 求单源最短路径,可以检查是否存在负权的环。时间复杂度O(v*e)http://www.wutianqi.com/?p=1912Spfa 求单源最短路径,是中国人发明的哦。。 同bellman可以检代负权的环,时间复杂度O(k*e)http://www.wutianqi.com/?p=2285floyd 求任意两地的最短路径,时间复杂度O(n^3)http://www.wutianqi.com/?p=1903Bellman-Ford算 阅读全文
posted @ 2012-03-06 20:37 E_star 阅读(202) 评论(0) 推荐(0)
摘要: http://poj.org/problem?id=3259第一周的题,已经是第二周末了。。还没做完。。唉。。效率啊。。。就是一个简单的判断有无负权值的环。bellmen_ford做法View Code #include <iostream>#include <cstdio>#include <cstring>#define maxn 5240#define inf 0x7fffffffusing namespace std;struct node{ int u,v; int w;}g[maxn];int n,m,w;int dis[maxn];bool b 阅读全文
posted @ 2012-03-04 13:29 E_star 阅读(195) 评论(0) 推荐(0)
摘要: 卡特兰数 Catalan数卡特兰数前几项为 : 1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 58786, 208012, 742900, 2674440, 9694845, 35357670, 129644790, 477638700, 1767263190, 6564120420, 24466267020, 91482563640, 343059613650, 1289904147324, 4861946401452, ... 中文:卡特兰数 原理: 令h(1)=1,h(0)=1,catalan数满足递归式: h(n)= h(1... 阅读全文
posted @ 2012-03-03 21:09 E_star 阅读(353) 评论(0) 推荐(0)
摘要: 1000http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1000&cid=387水题,水过》注意一下,把第一个数标记下来。否则后面的a[n- 1]和a[0]处理是会影响结果1001http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1001&cid=387才开始想开个二维字符型数组一个一个的读出来,然后按字符排序,结果管开数组就已经不行了。。太大了。。后来是边读边比较,结果果断的TLE了好几次。。最后我又记录最小的字符的位置,结果还是TLE.. 阅读全文
posted @ 2012-03-03 20:34 E_star 阅读(261) 评论(0) 推荐(0)
摘要: http://poj.org/problem?id=186题意就是转化成求最短路的模型,不过这里是求最长应该。以前做最短路基本上都是用Dijkstra()对于其他几个算法没有弄的明白,所以做起来比较吃力。。。简介:SPFA(Shortest Path Faster Algorithm)是Bellman-Ford算法的一种队列实现,减少了不必要的冗余计算。算法大致流程是用一个队列来进行维护。 初始时将源加入队列。 每次从队列中取出一个元素,并对所有与他相邻的点进行松弛,若某个相邻的点松弛成功,则将其入队。 直到队列为空时算法结束。它可以在O(kE)的时间复杂度内求出源点到其他所有点的最短路径,可 阅读全文
posted @ 2012-03-03 11:25 E_star 阅读(319) 评论(2) 推荐(0)
摘要: http://poj.org/problem?id=3083题意就读了很长时间还是没读懂。。。无语。。。懂了之后才开始自己写了一个果断tle郁闷死我了。。最后看了别人很巧妙的方法。。0s过。。。牛啊。不过就是不明白,为什么初始方向没标记也能过。默认的也能过。。。默认初始方向为0的View Code #include <cstdio>#include <cstring>#include <queue>#include <iostream>#define maxn 50using namespace std;int vt[maxn][maxn];ch 阅读全文
posted @ 2012-03-02 22:47 E_star 阅读(190) 评论(0) 推荐(0)
摘要: http://poj.org/problem?id=2049好纠结的一道题,刚拿过体来就已经懵了。这个图的信息到底该怎么存啊。。。纠结。看了别人的思路才A的。。he,ve两个数组分别存放这平行于x轴,y轴的墙,门信息。。。dis存储到达该点的最端距离。View Code #include <cstdio>#include <cstring>#include <queue>#define maxn 250#define inf 999999999using namespace std;struct node//优先队列的写法{ int x,y; int len 阅读全文
posted @ 2012-03-01 20:30 E_star 阅读(273) 评论(0) 推荐(0)
摘要: View Code #include <cstdio>#include <cstring>#include <iostream>#include <functional>#include <queue>using namespace std;int ar[13] = {14,10,56,7,83,22,36,91,3,47,72,0};struct cmp1{ bool operator ()(int &a,int &b) { return a > b;//以后面的b为准a》b所以小的先出来 }};struct 阅读全文
posted @ 2012-03-01 16:17 E_star 阅读(283) 评论(0) 推荐(0)
摘要: http://poj.org/problem?id=3278可能写DFS写的比较习惯吧,每次只要遇到搜索提就会用DFS写。结果DFS版本各种剪枝后还是TLE郁闷。。求用dfs过的大牛代码。。后来用了bfs中间还是出了点小问题,考虑不认真造成的。BFSView Code #include <iostream>#include <cstring>#include <cstdio>#include <queue>using namespace std;int ans,s,e;bool visit[100007];struct node{ int pos 阅读全文
posted @ 2012-02-29 08:55 E_star 阅读(216) 评论(0) 推荐(0)
摘要: http://poj.org/problem?id=2993上一周的训练还没做完,唉。只能延续第一周的训练计划了。和pku2996正好过程相反。。。谢模拟题实在是太费劲了。。细节细节注意。View Code #include <iostream>#include <cstdio>#include <cstring>using namespace std;char str[20][40];int main(){ int i,j,k,l; int len; //首先排除字母构造整个表 for (i = 0; i < 17; i += 2) { for (. 阅读全文
posted @ 2012-02-28 21:06 E_star 阅读(297) 评论(0) 推荐(0)
摘要: 1001http://acm.sdut.edu.cn/web/problem.php?action=showproblem&problemid=2389卡精度的题目,第一次的WA后就想到了应该是卡精度的问题,可是以前没接触过eps怎么用,于是就纠结在了eps的考虑上,好不容易弄好了。可是还是WA结果我真的就死心了,于是就去做最小生成树的那个题(后来还是纠结了,,唉悲剧啊、。。)今天拿来,就是加了个tmp数组的出事化。。就A了。。唉。每次比赛时对于时间的把握,以及拿过题目来之后思路的整理,都还不够完善。。需要锻炼。View Code #include <iostream>#i 阅读全文
posted @ 2012-02-27 21:07 E_star 阅读(219) 评论(0) 推荐(0)
摘要: http://poj.org/problem?id=2996题意很难理解。给你一个棋盘,分白黑双方,白的用大写字母表示,黑的用小写字母表示。("K" (King), "Q" (Queen), "R" (Rook), "B" (Bishop), "N" (Knight), or "P" (Pawn))然后给出位置的描述方法:a,b,c,d,e,f,g,h分表代表列 1--8 分别代表行。然后进行描述。注意:这里的矩形,最下边是第一行。还有对于白色,同一个棋子行数小得先表示例如样 阅读全文
posted @ 2012-02-26 11:11 E_star 阅读(237) 评论(0) 推荐(0)
摘要: http://poj.org/problem?id=1573一个原来做过的模拟题,大早上做题就是头脑清楚啊。1Y..呵呵。。View Code #include <iostream>#include <cstring>#include <cstdio>#define maxn 107using namespace std;char str[maxn][maxn];bool visit[maxn][maxn];//标记是否已经走过int map[maxn][maxn];//存储到达ij这点时走了多少步int main(){ int n,m,s,i,j; int 阅读全文
posted @ 2012-02-26 09:49 E_star 阅读(215) 评论(0) 推荐(0)
摘要: http://poj.org/problem?id=2632唉。。做模拟题一定要细心啊。才开始自己吧题意读错了,以为向左右转后还要走呢。调了很长时间还是没有过样例,最后又看了一遍题目才发现,原来是原地打转。悲剧啊。还有就是对于tagp[a].mark的判断,if 必须配有els否则上一步对mark的改变会影响到下一步的处理。唉。。。这样的小错误在模拟题中是很难检查的。。唉。。费劲啊。View Code #include <iostream>#include <cstdio>#include <cstring>#define maxn 10007using n 阅读全文
posted @ 2012-02-25 22:08 E_star 阅读(318) 评论(0) 推荐(0)