题目链接: http://poj.org/problem?id=1860

找正环,找最长路,水题,WA了两天了。。

#include <stdio.h>
#include <string.h> struct Edge
{
int u, v;
double r, c;
}edge[]; int rear, n, m, s;
double v, dist[]; bool bellman_ford()
{
memset(dist, , sizeof(dist));
dist[s] = v;
for(int i = ; i < n; i++)
for(int j = ; j < rear; j++)
if(dist[edge[j].v] < (dist[edge[j].u]-edge[j].c) * edge[j].r)
dist[edge[j].v] = (dist[edge[j].u]-edge[j].c) * edge[j].r; for(int j = ; j < rear; j++)
if(dist[edge[j].v] < (dist[edge[j].u]-edge[j].c) * edge[j].r)
return ;
return ;
} int main()
{
int a, b;
double rab, cab, rba, cba;
while(scanf("%d %d %d %lf", &n, &m, &s, &v) != EOF)
{
rear = ;
while(m--)
{
scanf("%d %d %lf %lf %lf %lf", &a, &b, &rab, &cab, &rba, &cba);
edge[rear++] = (struct Edge){a, b, rab, cab};
edge[rear++] = (struct Edge){b, a, rba, cba};
}
printf("%s\n", bellman_ford() ? "YES" : "NO");
}
return ;
}

POJ 1860 Currency Exchange 毫无优化的bellman_ford跑了16Ms,spfa老是WA。。的更多相关文章

  1. 最短路(Bellman_Ford) POJ 1860 Currency Exchange

    题目传送门 /* 最短路(Bellman_Ford):求负环的思路,但是反过来用,即找正环 详细解释:http://blog.csdn.net/lyy289065406/article/details ...

  2. POJ 1860 Currency Exchange / ZOJ 1544 Currency Exchange (最短路径相关,spfa求环)

    POJ 1860 Currency Exchange / ZOJ 1544 Currency Exchange (最短路径相关,spfa求环) Description Several currency ...

  3. POJ 1860 Currency Exchange + 2240 Arbitrage + 3259 Wormholes 解题报告

    三道题都是考察最短路算法的判环.其中1860和2240判断正环,3259判断负环. 难度都不大,可以使用Bellman-ford算法,或者SPFA算法.也有用弗洛伊德算法的,笔者还不会SF-_-…… ...

  4. POJ 1860 Currency Exchange 最短路+负环

    原题链接:http://poj.org/problem?id=1860 Currency Exchange Time Limit: 1000MS   Memory Limit: 30000K Tota ...

  5. POJ 1860 Currency Exchange【bellman_ford判断是否有正环——基础入门】

    链接: http://poj.org/problem?id=1860 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...

  6. POJ 1860 Currency Exchange (最短路)

    Currency Exchange Time Limit:1000MS     Memory Limit:30000KB     64bit IO Format:%I64d & %I64u S ...

  7. poj - 1860 Currency Exchange Bellman-Ford 判断正环

    Currency Exchange POJ - 1860 题意: 有许多货币兑换点,每个兑换点仅支持两种货币的兑换,兑换有相应的汇率和手续费.你有s这个货币 V 个,问是否能通过合理地兑换货币,使得你 ...

  8. POJ 1860 Currency Exchange (Bellman-Ford)

    题目链接:POJ 1860 Description Several currency exchange points are working in our city. Let us suppose t ...

  9. POJ 1860 Currency Exchange (最短路)

    Currency Exchange Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 60000/30000K (Java/Other) T ...

随机推荐

  1. jitsi

    http://code.csdn.net/openkb/p-Jitsi https://download.jitsi.org/jitsi/nightly/ https://download.jitsi ...

  2. [Javascript] Gradient Fills on the HTML5 Canvas

    window.onload = function() { var canvas = document.getElementById("canvas"), context = can ...

  3. 场景类(CCSence)

    场景与流程控制 在图2-1中,每一个节点中显示的内容相对不变.通常,我们把这些内容相对不变的游戏元素集合称作场景(scene),把游戏在场景之间切换的过程叫做流程控制(flow control). 在 ...

  4. 使用split进行分割时遇到特殊字符的问题

    使用split分割时: String[] a="aa|bb|cc".split("|"); output: [a, a, |, b, b, |, c, c] 先 ...

  5. 通过JSTL用表格的形式显示

    <%@ page language="java" import="java.util.*, cn.hncu.domain.*" pageEncoding= ...

  6. (原创)如何在spannableString中使用自定义字体

    最近在做车联网的产品,主打的是语音交互和导航功能,UI给的导航界面可真是够酷炫的.但麻烦的事情也来了,里面的一句话居然用到了三种字体.界面如图所示: 从图中可以看出 500m左前方行驶 居然使用了三种 ...

  7. 集合练习——Map部分

    练习: 输入诗的名称查询出诗的内容,当输入exit时,退出程序,“春晓”,“静夜思”,“鹅”. package CollectionPart; public class Poetry { privat ...

  8. Web Services之SOAP学习

    Web Services之SOAP [toc] 什么是SOAP SOAP(Simple Object Access Protocol)简单对象访问协议是在分散或分布式的环境中交换信息的简单的协议,是一 ...

  9. Web网站与Web应用程序区别

    创建时的目录结构不同. WEB应用程序一般处理程序有命名空间,而网站中的没有.(因为应用程序最后要编译成一个DLL文件,会产生命名冲突,而网站每个页面会编译成每一个的DLL,不会文件内产生全名冲突). ...

  10. ffmpeg之YUYV转RGB ARM使用流程分析

    本例基于3.2.2 ffmpeg 一.应用调用API 二.头文件包含的API接口 对应于libswscale.so.libswscale.so.4.libswscale.so.4.2.100中 sws ...