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) 编辑
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) 编辑
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) 编辑
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) 编辑
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) 编辑
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) 编辑
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) 编辑
uva 10048【Audiophobia】
摘要:这一题不错。。。将floyd变了变形。。。代码如下: 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 5 int point,street,que; 6 int g[1010][1010]; 7 int cas; 8 9 bool init()10 {11 scanf("%d%d%d",&point,&street,&que);12 if(point == 0&&street == 0&&que ==
阅读全文
posted @
2012-04-16 11:16
Shirlies
阅读(228)
推荐(0) 编辑
uva 567【Risk】
摘要:求最短路,Floyd算法,简单的应用不过题目真的很晦涩。。。第一个数x表示与第i个数(通俗一点,第i行,其实也是标号为i的点)相邻的点的个数,然后后面有x个值。代码如下: 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 5 int g[22][22]; 6 int n; 7 8 bool init() 9 {10 int num;11 for(int i = 1;i <= 20;i ++)12 {13 for(int j = 1;j <= 20;j ++)14 .
阅读全文
posted @
2012-04-15 21:27
Shirlies
阅读(262)
推荐(0) 编辑