随笔分类 -  最短路

hdu 4435 charge-station
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4435有题意可以知道 对应第k个城市 即使前(k-1)个城市都建立加油站 也没有在第k个城市建立加油站花的钱多思路 :如果全部都建立加油站 还是不能满足条件的话 则说明没有解决方案否则 从后面逐个向前尝试看是否可以不建立对于 是否能达到目的 我用的方法比较麻烦两次 spfa 分别求到某个城市时 还未在此站加油(也可能没有加油站)最多可以有多少油 和 在某个城市想回来的话最少需要的油量每个点必须满足 有的油量可以回来代码:#include<iostream>#include<cstdio> 阅读全文
posted @ 2012-11-02 18:54 夜-> 阅读(154) 评论(0) 推荐(0)
1160. Network
摘要:http://acm.timus.ru/problem.aspx?space=1&num=1160最短路变形 水题 spfa代码:#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<string>#include<vector>#include<map>#include<queue>#include<stack>#include<cmath>#define LL 阅读全文
posted @ 2012-10-25 16:36 夜-> 阅读(320) 评论(0) 推荐(0)
1450. Russian Pipelines
摘要:http://acm.timus.ru/problem.aspx?space=1&num=1450水题 最短路 spfa代码:#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<string>#include<vector>#include<map>#include<queue>#include<stack>#include<cmath>#define LL lo 阅读全文
posted @ 2012-10-25 16:12 夜-> 阅读(254) 评论(0) 推荐(0)
1651. Shortest Subchain
摘要:http://acm.timus.ru/problem.aspx?space=1&num=1651题意:给出链上点的顺序 要求找一条子链 满足三个条件1,起点和终点和原链一样2,边的顺序和原始顺序一致3,最短思路:如果去掉第二个条件的话 就变成了最简单的最短路了 由于第二个条件的限制 要按给的边的顺序依次更新然后重要的就是记录路径代码及其注释:#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<string>#includ 阅读全文
posted @ 2012-10-24 16:08 夜-> 阅读(324) 评论(0) 推荐(0)
1205. By the Underground or by Foot?
摘要:http://acm.timus.ru/problem.aspx?space=1&num=1205spfa代码:#include<iostream>#include<cstdio>#include<cstring>#include<string>#include<vector>#include<map>#include<cmath>#include<queue>#include<stack>#include<algorithm>using namespace std; 阅读全文
posted @ 2012-10-22 17:18 夜-> 阅读(589) 评论(0) 推荐(0)
poj 1734 Sightseeing trip
摘要:http://poj.org/problem?id=1734比着别人的代码写的 自己对floyd的理解还是不深刻呀#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<string>#include<vector>#include<set>#include<queue>#include<stack>#include<cmath>#define LL long longusi 阅读全文
posted @ 2012-08-18 20:21 夜-> 阅读(173) 评论(0) 推荐(0)
poj 3255 Roadblocks
摘要:http://poj.org/problem?id=3255第k短路#include<iostream>#include<cstdio>#include<algorithm>#include<cmath>#include<queue>#include<string.h>using namespace std;const int N=5001;const int M=200005;const int MAX=0x5fffffff;int head[N];struct node{ int j,k; int next;}side 阅读全文
posted @ 2012-08-07 10:07 夜-> 阅读(214) 评论(0) 推荐(0)
poj 2449 Remmarguts' Date
摘要:http://poj.org/problem?id=2449第k短路 刚开始上网找了分标准解法 没看懂呀 汗 然后看别人都用了A*算法 我也不知道是什么东西如果我们用队列枚举的话 当第k次出现终点 则这时就是到终点的第k短路但是这样队列是承受不住的 因为数据会太多对于这道题 思路好像基本上就是构造一个函数 f(i)=g(i)+h(i) g为出发点到i的最短距离 h为终点到i的最短距离f 为他们的和但每次取f最小的点进行更新直到终点出现第k次 既为答案#include<iostream>#include<cstdio>#include<algorithm>#i 阅读全文
posted @ 2012-08-07 09:37 夜-> 阅读(158) 评论(0) 推荐(0)
poj 3621 Sightseeing Cows
摘要:http://poj.org/problem?id=3621分数规划+二分 最优比率环 不是很难 本题中没有说明从哪个点开始 不过好像默认为1就可以过 poj数据又水了里面的用spfa判定部分还是不太懂代码及其注释:#include<iostream>#include<stdio.h>#include<algorithm>#include<math.h>#include<queue>#include<string.h>using namespace std;const double eps=1e-5;const int N 阅读全文
posted @ 2012-08-06 10:42 夜-> 阅读(186) 评论(0) 推荐(0)
poj 1125 Stockbroker Grapevine
摘要:http://poj.org/problem?id=1125#include<iostream>#include<cstdio>#include<cstdlib>#include<ctime>#include<queue>#include<map>#include<cstring>#include<algorithm>#define LL long longusing namespace std;const int N=105;const int MAX=100000;int dist[N][N]; 阅读全文
posted @ 2012-08-05 16:20 夜-> 阅读(130) 评论(0) 推荐(0)
hdu 1874 通畅工程续
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1874很水#include<iostream>#include<cstdio>#include<cstdlib>#include<ctime>#include<queue>#include<map>#include<cstring>#include<algorithm>#define LL long longusing namespace std;const int N=205;const int MAX=0x5f 阅读全文
posted @ 2012-08-05 15:21 夜-> 阅读(136) 评论(0) 推荐(0)
hdu 4318 Power transmission
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4318很裸的spfa#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<cmath>#include<map>#include<queue>#include<cmath>#define LL long longusing namespace std;const int N=50040;const double 阅读全文
posted @ 2012-07-28 07:59 夜-> 阅读(185) 评论(0) 推荐(0)
poj 3259 Wormholes
摘要:http://poj.org/problem?id=3259#include<iostream>#include<stdio.h>#include<algorithm>#include<math.h>#include<string.h>#define Max 0xfffffffusing namespace std;struct node{ int i,j;}mem[5500];int main(){ //freopen("r","data.txt",stdin); int n,m,w,M; i 阅读全文
posted @ 2012-03-24 20:38 夜-> 阅读(146) 评论(0) 推荐(0)
poj 2253 Frogger
摘要:http://poj.org/problem?id=2253#include<iostream>#include<stdio.h>#include<algorithm>#include<math.h>#include<string.h>using namespace std;struct node{ int x,y;}mem[1005];bool visited[1005];double dis[1005];inline double disoftwopoints(int i,int j){ return sqrt((double(m 阅读全文
posted @ 2012-03-23 19:36 夜-> 阅读(153) 评论(0) 推荐(0)