POJ 1860 Currency Exchange 毫无优化的bellman_ford跑了16Ms,spfa老是WA。。
题目链接: 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。。的更多相关文章
- 最短路(Bellman_Ford) POJ 1860 Currency Exchange
题目传送门 /* 最短路(Bellman_Ford):求负环的思路,但是反过来用,即找正环 详细解释:http://blog.csdn.net/lyy289065406/article/details ...
- POJ 1860 Currency Exchange / ZOJ 1544 Currency Exchange (最短路径相关,spfa求环)
POJ 1860 Currency Exchange / ZOJ 1544 Currency Exchange (最短路径相关,spfa求环) Description Several currency ...
- POJ 1860 Currency Exchange + 2240 Arbitrage + 3259 Wormholes 解题报告
三道题都是考察最短路算法的判环.其中1860和2240判断正环,3259判断负环. 难度都不大,可以使用Bellman-ford算法,或者SPFA算法.也有用弗洛伊德算法的,笔者还不会SF-_-…… ...
- POJ 1860 Currency Exchange 最短路+负环
原题链接:http://poj.org/problem?id=1860 Currency Exchange Time Limit: 1000MS Memory Limit: 30000K Tota ...
- POJ 1860 Currency Exchange【bellman_ford判断是否有正环——基础入门】
链接: http://poj.org/problem?id=1860 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...
- POJ 1860 Currency Exchange (最短路)
Currency Exchange Time Limit:1000MS Memory Limit:30000KB 64bit IO Format:%I64d & %I64u S ...
- poj - 1860 Currency Exchange Bellman-Ford 判断正环
Currency Exchange POJ - 1860 题意: 有许多货币兑换点,每个兑换点仅支持两种货币的兑换,兑换有相应的汇率和手续费.你有s这个货币 V 个,问是否能通过合理地兑换货币,使得你 ...
- POJ 1860 Currency Exchange (Bellman-Ford)
题目链接:POJ 1860 Description Several currency exchange points are working in our city. Let us suppose t ...
- POJ 1860 Currency Exchange (最短路)
Currency Exchange Time Limit : 2000/1000ms (Java/Other) Memory Limit : 60000/30000K (Java/Other) T ...
随机推荐
- String.Format使用方法
1.作为參数 名称 说明 Format(String, Object) 将指定的 String 中的格式项替换为指定的 Object 实例的值的文本等效项. Format(String, ...
- LoC
对于图片.Flash等非文本文件统计文件数量.文件大小: 对于文本文件统计文件数量.文本行数.字符数:
- 【转】VS2010中使用AnkhSvn
今天想到要在自己的开发环境IDE(Visual Studio 2010)中安装一个代码管理器的插件,本人在使用VS2005的时候一直都是使用AnkhSvn-2.1.7444.278这版本,使用过程中也 ...
- Dynamic SQL--官方文档
https://ibatis.apache.org/docs/dotnet/datamapper/ch03s09.html 3.9. Dynamic SQL A very common problem ...
- shell记录
查看linux服务器有哪些人曾经ssh登陆过,以及他们的登录信息 who查看当前正在ssh链接中的 last查看最近被链接过的 who last netstat -nltp -an ...
- Windows redis集群搭建
一.Windows下Redis安装 下载地址https://github.com/dmajkic/redis/downloads,下载到的Redis支持32bit和64bit.根据自己实际情况选择,本 ...
- 【转】ArrayList的toArray
[转]ArrayList的toArray ArrayList提供了一个将List转为数组的一个非常方便的方法toArray.toArray有两个重载的方法: 1.list.toArray(); 2.l ...
- (转)ASP.NET禁用刷新重复提交Backspace键
在网页制作中,由于Backspace键可以回退到上一个网页,利用了缓存的数据,从而导致一些错误发生.浏览器的后退按钮使得我们能够方便地返回以前访问过的页面,它无疑非常有用.但有时候我们不得不关闭这个功 ...
- IOC主要接口
- iOS开发——扫描二维码——工具类
(代码已测试好,空闲时间更新……)