最短路
syyyyyw
acmer一枚
展开
-
poj 1860
这是第一次做最短路的题 n就是钱的种类,就是点 m*2就是边 要想有提高,就是有正环 但要先交税,有可能有负边 于是就用Bellman-Ford 看了kuanbin巨巨写的,对怎么判断负环有了深刻的理解 代码如下 #include #include #include #include using namespace std; const int maxn=105; double d原创 2017-08-19 08:07:48 · 183 阅读 · 0 评论 -
poj 1065
第三道最短路的题 第一次写dijkstra; 这个题一开始一直没读懂题意; 后来明白了,因为但是如果他和某个地位较低的人进行了交易,地位较高的的人不会再和他交易,他们认为这样等于是间接接触,反过来也一样。因此你需要在考虑所有的情况以后给他提供一个最好的方案。 这意味着只能交易一次 剩下的就是枚举加dijkstra; 推荐两个题解 我是结合着两个,按照我的理解写的 点击打开链接原创 2017-08-21 20:28:36 · 186 阅读 · 0 评论 -
poj 2253(dijkstra暂时不明白)
有两种写法 但是我还是有点不太理解为什么要用最短路。。。。。。 一种是floyd 我能理解,但是dijkstra我有点晕,后面的我明白,但是我不懂为什么每次还要再取最小的边; #include #include #include #include #include using namespace std; const int INF=1e9+7; double cost[205][205];原创 2017-08-22 08:36:41 · 177 阅读 · 0 评论 -
poj 1125
用floyd求,代码如下 #include #include #include #include using namespace std; const int INF=1e9+7; int cost[105][105]; int main() { int n; while(~scanf("%d",&n)){ if(n==0) break; for(int i=1;i<=n;i++)原创 2017-08-22 12:19:40 · 164 阅读 · 0 评论 -
poj 2240
代码如下 #include #include #include #include #include using namespace std; const int INF=1e9+7; map p; double cost[35][35]; int main() { int n,cnt=0; while(~scanf("%d",&n)){ if(n==0) break; else {原创 2017-08-22 13:35:50 · 182 阅读 · 0 评论 -
poj 2139
代码如下 #include #include #include #include using namespace std; int d[305][305]; int a[305]; int main() { int n,m; scanf("%d%d",&n,&m); for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){原创 2018-03-10 11:26:04 · 110 阅读 · 0 评论 -
poj 3268
代码如下 #include #include #include #include using namespace std; const int maxn=1007; const int INF=1e9+7; int n,m,x; int used[maxn]; int cost1[maxn][maxn],cost2[maxn][maxn]; int d1[maxn],d2[maxn]; void原创 2018-03-13 13:56:37 · 190 阅读 · 0 评论 -
poj 3259
题意是问你从某个点出发,回来的时间却是你出发之前的时间 因为有虫洞,所以有负边 用Bellman_Ford判断负环 但是我发现没起点; 看了别人的,就不用初始化为0了,剩下的都是一样的; 这说明我对最短路的理解还是不透彻; 第二个最短路的题目 代码如下 #include #include #include #include using namespace std; struct e原创 2017-08-19 09:18:24 · 113 阅读 · 0 评论