Shirlies
宁静专注认真的程序媛~
posts - 222,comments - 49,views - 71万

随笔分类 -  acm_图论

1 2 下一页
poj 3352【Road Construction】
摘要:狂晕,是我做题太少了吧?我竟然直接按输入输出的模式做题,即输出“Output for Sample Input 1”,呜呜,WA了几次就是因为这个。。。。。。。。。。。。。。。。。。。。。。。。。。。View Code 1 #include <iostream> 2 #include <vector> 3 #include <cstring> 4 #include <algorithm> 5 using namespace std; 6 7 const int maxN = 1000+10; 8 int low[maxN]; 9 int DFN[ 阅读全文
posted @ 2012-09-14 20:51 Shirlies 阅读(220) 评论(0) 推荐(0) 编辑
poj 3177【Redundant Paths】
摘要:将图变成双连通图,缩点,考虑该点与其他点相连的个数,如果只有一条边与其他点相连,则需要加一条边,因为这里面的点只能通过一条边到其他点,加一条边让它们能够通过另一条边到达其他点。View Code 1 #include <iostream> 2 #include <cstring> 3 #include <vector> 4 using namespace std; 5 6 const int maxN = 5000+10; 7 int low[maxN]; 8 int DFN[maxN]; 9 int degree[maxN];10 int cnt;11 1 阅读全文
posted @ 2012-09-13 21:19 Shirlies 阅读(161) 评论(0) 推荐(0) 编辑
poj 2762【Going from u to v or from v to u?】
摘要:先用Tarjan求出强连通分量,其他算法也可以的,再缩点,然后从入度为0的点开始暴搜,如果深度达到强连通分量的个数即可行。这一题一定要注意一点:我用cin的时候TLE,该scanf就好了。。。View Code 1 #include <cstdio> 2 #include <cstring> 3 #include <vector> 4 using namespace std; 5 6 const int maxN = 1000 + 10; 7 vector<int> edge[maxN]; 8 int low[maxN]; 9 int stack 阅读全文
posted @ 2012-09-09 21:05 Shirlies 阅读(166) 评论(0) 推荐(0) 编辑
poj 2186【Popular Cows】1236【Network of Schools】2553【The Bottom of a Graph】
摘要:三种方法求极大强连通分支的算法,一题一种方法poj 2186 求牛被所有其它的牛崇拜的个数,在一个强连通分量里面的牛是互相崇拜的,所以如果这个强连通分支被其它牛崇拜那么这里面的牛都被其它牛崇拜.。。。这一题我用的Tarjan算法View Code 1 #include <iostream> 2 #include <cstring> 3 #include <vector> 4 using namespace std; 5 6 const int maxN = 10000+10; 7 int low[maxN]; 8 int stack[maxN],top; 9 阅读全文
posted @ 2012-09-08 22:14 Shirlies 阅读(254) 评论(0) 推荐(0) 编辑
poj 1659【Frogs' Neighborhood】
摘要:Havel-Hakimi定理http://blog.sina.com.cn/s/blog_818d3d930100wdv1.htmlhttp://hi.baidu.com/krdefndrsbbekmd/item/a7c58810f40156f8dceecab7View Code 1 #include <iostream> 2 #include <cstring> 3 #include <algorithm> 4 using namespace std; 5 6 struct node 7 { 8 int u; 9 int dg;10 }p[15];11 i 阅读全文
posted @ 2012-09-05 09:43 Shirlies 阅读(229) 评论(0) 推荐(0) 编辑
poj 3522【Slim Span】
摘要:题意:给你一个无向图,没有重边,没有自环,要你求该图中一颗生成树,但是这个生成树的最大边与最小边的差值要最小。如果固定一个最小边,求得最小生成树后,最大边也就知道了,其实这个也意味着在固定最小边的情况下最小生成树的最大边是固定的,可是为什么我们一定要求最小生成树呢,因为其他的生成树的最大边与最小边的差值要大于等于最小生成树的大小边之差,这个的原因大家可以自己仔细想想最小生成树的性质和次小生成树的求法(枚举每条最小生成树上的边,不要此条边求得的生成树,选最小一个就是了,这个就意味着次小生成树里面肯定有一条边要比最小生成树的大,其它的相同)。这样说来的话,我们只需将边排好序后,枚举每条边,并用Kr 阅读全文
posted @ 2012-09-02 12:29 Shirlies 阅读(208) 评论(0) 推荐(0) 编辑
poj 2728【Desert King】
摘要:我之前也没有搞过01规划,但是之前做过3621,3621这道题也用到了01规划,虽然我还是不太理解01规划,但是3621题解的推导过程给了我启示……∑cost[i]/∑len[i] <= ans∑cost[i] <= ans * ∑len[i]∑(cost[i] - ans * len[i]) <= 0当和小于0时说明ans需变小还有这一题目很自然就要用prim,题目只给了点的坐标和高度,而且点也不算太多,如果用Krustral要存的边会很多……而且第一个城市是首都,(there will be only one way to connect each village to 阅读全文
posted @ 2012-08-30 12:43 Shirlies 阅读(182) 评论(0) 推荐(0) 编辑
poj 3613【Cow Relays】
摘要:首先看题解,看到的是floyd,然后就往floyd方向去想,想不咋通,之后就问了队长,队长解释了一下就清楚了这一题用的是floyd和二分的思想,如果只是floyd的思想就是求任意两点之间距离为k(1<=k<=N)条边的最短距离,然后在此基础上求k+1条边的最短距离…… 1 #include <cstdio> 2 #include <cstring> 3 4 const int maxlen = 1000+10; 5 int N,T,S,E; 6 int map[maxlen][maxlen]; 7 int sign[maxlen]; 8 int tmp[ma 阅读全文
posted @ 2012-08-27 13:45 Shirlies 阅读(256) 评论(0) 推荐(0) 编辑
hdu 1507【Uncle Tom's Inherited Land*】
摘要:#include <cstdio>#include <cstring>#include <vector>using namespace std;vector<int> land[100];int link[100];bool vis[100];int g[110][110];bool vis2[100];int pond[100];int n,m,k;bool can(int x){ int len = land[x].size(); for(int i = 0;i < len;i ++) { int t = land[x].at(i); 阅读全文
posted @ 2012-05-13 11:24 Shirlies 阅读(306) 评论(0) 推荐(0) 编辑
hdu 1528【Card Game Cheater】
摘要:#include <iostream>#include <cstring>#include <string>#include <vector>using namespace std;vector<int> card[100];int n;bool vis[100];int link[100];int num_pre(char a){ static string pre = "23456789TJQKA"; for(int i = 0;i < pre.size();i ++) { if(a == pre.at( 阅读全文
posted @ 2012-05-13 09:40 Shirlies 阅读(412) 评论(0) 推荐(0) 编辑
hdu 2819【Swap】
摘要:不错的一道题目,但是中途我还是出问题了,代码中有注释代码如下: 1 #include <cstdio> 2 #include <cstring> 3 4 struct node 5 { 6 int x,y; 7 }ans[1005]; 8 9 int g[200][200];10 bool vis[200];11 int link[200];12 int match[200];13 int n;14 15 void init()16 {17 memset(link, -1,sizeof(link));18 }19 20 bool can(int x)21 {22 f.. 阅读全文
posted @ 2012-05-11 15:47 Shirlies 阅读(266) 评论(0) 推荐(0) 编辑
hdu 1150【Machine Schedule】
摘要:有时候都不太想写博客了,(~ o ~)~zZ这一题是纯粹的二分图匹配,不过要注意一点哈“At the beginning they are both work at mode_0”,所以要判断一下两点连接的时候是不是存在0这个点if(a && b)pro[a].push_back(b);代码如下: 1 #include <cstdio> 2 #include <cstring> 3 #include <vector> 4 using namespace std; 5 6 int vis[200]; 7 int link[200]; 8 vec 阅读全文
posted @ 2012-05-10 13:19 Shirlies 阅读(217) 评论(0) 推荐(0) 编辑
uva 10330【 Power Transmission】
摘要:第一道网络流的题目,我是看这个讲解的http://www.nocow.cn/index.php/%E7%BD%91%E7%BB%9C%E6%B5%81Edmonds-Karp 算法主要是顶点有值限制,所以可以将一个点分成两个点a和a',它们两个之间的容量就是顶点的值代码如下: 1 #include <cstdio> 2 #include <cstring> 3 #include <queue> 4 using namespace std; 5 6 const int maxn = 300; 7 const int inf = 0x7fffffff; 阅读全文
posted @ 2012-05-10 00:14 Shirlies 阅读(277) 评论(0) 推荐(0) 编辑
hdu 2722【Here We Go(relians) Again】
摘要:表示很无语的一题,纯粹意义上的字符处理,晕...用优先队列做的,时间0ms...代码如下: 1 #include <cstdio> 2 #include <cstring> 3 #include <queue> 4 using namespace std; 5 6 struct node 7 { 8 int u,v; 9 int w; 10 }p[5000]; 11 int d[1000]; 12 int n,m; 13 int num; 14 int first[5000]; 15 int nextt[5000]; 16 typedef pair<i 阅读全文
posted @ 2012-05-04 21:13 Shirlies 阅读(344) 评论(0) 推荐(0) 编辑
hdu 2680
摘要:心血来潮,用优先队列实现了这个Dijkstra,顺便练练静态链表,不过结果也蛮不错的,在acm steps里面是93msA的,在外面却是109ms,排名很靠前,好开心,不过也郁闷,竟然有人31ms过了,汗...到底是怎么样的一个牛人啊......代码如下: 1 #include <cstdio> 2 #include <cstring> 3 #include <queue> 4 using namespace std; 5 6 const int maxn = 20000 + 100; 7 int n,m,endd; 8 typedef pair<in 阅读全文
posted @ 2012-05-02 20:44 Shirlies 阅读(287) 评论(0) 推荐(0) 编辑
hdu 1874【畅通工程续】
摘要:在此郑重的向南柯小朋友表示我的感谢!!如果不是他告诉我输入的时候需要处理if(g[a][b] == -1 || g[a][b] > w)g[a][b] = g[b][a] = w;(从一个点到另外一个点竟然有好几种选择,囧,我们仅仅需要考虑最小的就ok了)这个东西的话,相信我是找不出问题来的.......也向他表示感谢HDU today这一题也是他找出了问题,就是起点和目的地相同的情况我没有考虑......代码如下: 1 #include <cstdio> 2 #include <cstring> 3 4 int g[200][200]; 5 int vis[20 阅读全文
posted @ 2012-05-02 18:29 Shirlies 阅读(155) 评论(0) 推荐(0) 编辑
uva 515
摘要:这一题是访别人写的,第一道差分约束的题目,但是现在做一题就得整理模板了。。。至少把它的思想好好记住http://blog.sina.com.cn/s/blog_60707c0f0100xht7.html这个讲差分约束的,算法导论上面也有,还是比较喜欢看纸质版的。代码来自http://www.cnblogs.com/staginner/archive/2011/10/20/2218421.html 阅读全文
posted @ 2012-04-20 15:31 Shirlies 阅读(193) 评论(0) 推荐(0) 编辑
uva 10986
摘要:最短路Dijkstra算法,用优先队列。。。代码如下: 1 #include <cstdio> 2 #include <cstring> 3 #include <queue> 4 #include <vector> 5 using namespace std; 6 7 const int maxn = 50010; 8 struct node 9 {10 int v;11 int w;12 };13 14 typedef pair<int,int> pii;15 vector<node> p[2*maxn];16 int 阅读全文
posted @ 2012-04-18 17:14 Shirlies 阅读(358) 评论(0) 推荐(0) 编辑
uva 10801【Lift Hopping】
摘要:表示对这类题目没feel,抽象。。。参考别人的代码后写出来的,顺便练习了一下FIFO队列实现Bellman-ford算法。。。代码如下: 1 #include <cstdio> 2 #include <cstring> 3 #include <queue> 4 #include <cmath> 5 using namespace std; 6 7 int g[6][105]; 8 int n,k; 9 int t[6];10 int d[105];11 int v[105];12 13 void init()14 {15 for(int i = 阅读全文
posted @ 2012-04-17 21:09 Shirlies 阅读(265) 评论(0) 推荐(0) 编辑
uva 10099【The Tourist Guide】
摘要:忠诚的告诉大家:uva上的题目一定要看清楚格式啊,格式错误也是WA啊,~~~~(>_<)~~~~ 因为一个换行符WA了几次。。。Dijkstra的变形。。。求一条路上的最小值然后取多条路中的最大值。。。代码如下: 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 5 int g[110][110]; 6 int v[110],d[110]; 7 int N,R; 8 int start,end,per; 9 int cas;10 11 bool init()12 { 阅读全文
posted @ 2012-04-17 19:53 Shirlies 阅读(234) 评论(0) 推荐(0) 编辑

1 2 下一页
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示