POJ 1860: Currency Exchange 【SPFA】
套汇问题,从源点做SPFA,如果有一个点入队次数大于v次(v表示点的个数)则图中存在负权回路,能够套汇,如果不存在负权回路,则判断下源点到自身的最长路是否大于自身,使用SPFA时松弛操作需要做调整
#include<iostream>
#include<cstdio>
#include<string.h>
#include <stdlib.h>
#include <math.h>
using namespace std;
const int maxn=2000;
double dist[maxn]={0},rate[maxn][maxn]={{0}},ope[maxn][maxn]={{0}},v;
int n,m,s,cnt[maxn]={0};
bool spfa(int scr)
{
int l=0,r=1,que[10000]={0},visit[maxn]={0},temp;
que[++l]=scr;
dist[scr]=v;
cnt[scr]=1;
while(l<=r)
{
temp=que[l++];
visit[temp]=0;
for(int i=1;i<=n;i++)
{
if (rate[temp][i]>0 &&dist[i]<(dist[temp]-ope[temp][i])*rate[temp][i])
{
dist[i]=(dist[temp]-ope[temp][i])*rate[temp][i];
if (visit[i]==0)
{
visit[i]=1;
que[++r]=i;
cnt[i]++;
if (cnt[i]>=n)returntrue;
}
}
}
}
return dist[s]>v;
}
int main()
{
int x,y;
scanf("%d%d%d%lf",&n,&m,&s,&v);
for(int i=1;i<=m;i++)
{
scanf("%d%d",&x,&y);
scanf("%lf%lf%lf%lf",&rate[x][y],&ope[x][y],&rate[y][x],&ope[y][x]);
}
if(spfa(s))printf("YES\n");else printf("NO\n");
return 0;
}
POJ 1860: Currency Exchange 【SPFA】的更多相关文章
- POJ 1860 Currency Exchange【SPFA判环】
Several currency exchange points are working in our city. Let us suppose that each point specializes ...
- POJ 1860——Currency Exchange——————【最短路、SPFA判正环】
Currency Exchange Time Limit:1000MS Memory Limit:30000KB 64bit IO Format:%I64d & %I64u S ...
- 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,SPFA判圈。
Description Several currency exchange points are working in our city. Let us suppose that each point ...
- poj 1860 Currency Exchange (SPFA、正权回路 bellman-ford)
链接:poj 1860 题意:给定n中货币.以及它们之间的税率.A货币转化为B货币的公式为 B=(V-Cab)*Rab,当中V为A的货币量, 求货币S通过若干此转换,再转换为原本的货币时是否会添加 分 ...
- POJ 1860 Currency Exchange【bellman-Ford模板题】
传送门:http://poj.org/problem?id=1860 题意:给出每两种货币之间交换的手续费和汇率,求出从当前货币s开始交换回到s,能否使本金增多. 思路:bellman-Ford模板题 ...
- POJ 1860 Currency Exchange(SPFA+邻接矩阵)
( ̄▽ ̄)" #include<iostream> #include<cstdio> #include<cmath> #include<algori ...
- Poj 1860 Currency Exchange(Bellman-Ford,SPFA解单源最短路径问题)
一.题意 有多个货币交易点,每个只能互换两种货币,兑换的汇率不同,并收取相应的手续费.有N种货币,假定你拥有第S中,数量为V,有M个兑换点.问你能不能通过兑换操作使你最后拥有的S币比起始的时候多. 二 ...
- POJ 1860 Currency Exchange / ZOJ 1544 Currency Exchange (最短路径相关,spfa求环)
POJ 1860 Currency Exchange / ZOJ 1544 Currency Exchange (最短路径相关,spfa求环) Description Several currency ...
随机推荐
- 如何使用KeyChain保存和获取UDID
本文是iOS7系列文章第一篇文章,主要介绍使用KeyChain保存和获取APP数据,解决iOS7上获取不变UDID的问题.并给出一个获取UDID的工具类,使用方便,只需要替换两个地方即可. 一.iOS ...
- HDU 4044 GeoDefense (树形DP,混合经典)
题意: 给一棵n个节点的树,点1为敌方基地,叶子结点都为我方阵地.我们可以在每个结点安放炸弹,每点至多放一个,每个结点有ki种炸弹可选,且每种炸弹有一个花费和一个攻击力(1点攻击力使敌人掉1点hp). ...
- Window10 开启传统启动界面
Windows 10沿袭了Windows 8的快速启动,导致在启动过程中无法通过按F8进入启动选项,这样当系统遇到问题无法进入时根本无法通过进入安全模式等方式进行处理(当然通过其他一些工具还是能够引导 ...
- mysql Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nona
1. 操作mysql的时候提示如下错误 [Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and cont ...
- CAD交互绘制圆形批注(网页版)
js中实现代码说明: 动态拖放时的绘制事件: function DoDynWorldDrawFun(dX,dY,pWorldDraw,pData) { //自定义实体的GUID标识符 var sGui ...
- PAT (Basic Level) Practise (中文)- 1024. 科学计数法 (20)
PAT (Basic Level) Practise (中文)- 1024. 科学计数法 (20) http://www.patest.cn/contests/pat-b-practise/1024 ...
- xheditor的参数配置详解
2.2. 初始化参数列表 2.3. API函数接口列表 2.4. 上传程序开发规范 2.5. 插件开发指南 2.6. 皮肤设计指南 2.2. 初始化参数列表 初始化参数示例代码: $('#elm1') ...
- javaEE(6)_JSP
一.什么是JSP 1.JSP全称是Java Server Pages,它和servle技术一样,都是SUN公司定义的一种用于开发动态web资源的技术,只用JSP就可以开发动态web资源. 2.为什么J ...
- iOS面试集锦3
1.写一个NSString类的实现 + (id)initWithCString:(c*****t char *)nullTerminatedCString encoding:(NSStringEnco ...
- 企业版https
http://www.cocoachina.com/bbs/read.php?tid=194213