刚上来一堆英文着实有点蒙逼,仔细分析是一个Bellman的变形,只要能找出一个无限增大的环这个题就好解决了,我这里用的SPFA,用邻接链表进行储存,直接套用的模板,部分变量名字没有改的很好

#include <iostream>
#include<string.h>
#include <queue>
#include <vector>
using namespace std;
#define MAX 99999999;
double dis[1000+6];
double vis[1000+6];
int n;
double fir;
typedef struct
{
int x;
double rate;
double cost;
}point;
vector<point> p[1010];
int Spfa(int start)
{ queue<int> Q;
memset(vis, 0, sizeof(vis));
memset(dis, 0, sizeof(dis));
dis[start] = fir;
vis[start] = true;
Q.push(start);
while (!Q.empty()){
int temp = Q.front();
Q.pop();
vis[temp] = false;
for(int i=0; i<p[temp].size(); i++)
{
int v=p[temp][i].x;
double w=p[temp][i].rate;
double z=p[temp][i].cost;
if ((dis[temp]-z)*w > dis[v])
{
dis[v] = (dis[temp]-z)*w;
if(dis[start]>fir)
return true;
if (!vis[v])
{
Q.push(v);
vis[v] = true;
}
}
} }
return false;
}
int main()
{
int m,s; while(cin>>n>>m>>s>>fir)
{ point node;
int from,to;
double rab,rba,cab,cba;
for(int i=0;i<m;i++)
{
cin>>from>>to>>rab>>cab>>rba>>cba;
node.x=to;
node.rate=rab;
node.cost=cab;
p[from].push_back(node);
node.x=from;
node.rate=rba;
node.cost=cba;
p[to].push_back(node); }
int flag=0;
flag=Spfa(s);
if(flag)
cout<<"YES"<<endl;
else
cout<<"NO\n";
for(int i=1;i<n;i++)
p[i].clear();
}
return 0;
}

  

poj1860的更多相关文章

  1. POJ1860——Currency Exchange(BellmanFord算法求最短路)

    Currency Exchange DescriptionSeveral currency exchange points are working in our city. Let us suppos ...

  2. POJ-1860 Currency Exchange---Bellman-Ford判断正环

    题目链接: https://vjudge.net/problem/POJ-1860 题目大意: 我们的城市有几个货币兑换点.让我们假设每一个点都只能兑换专门的两种货币.可以有几个点,专门从事相同货币兑 ...

  3. POJ-1860(最短路问题,Bellman-Ford算法判正圈)

    Currency Exchange POJ-1860 这题其实是最短路问题的变形,但是这里不用求解最短路,而是求解路径中是否存在正圈.如果存在正圈则说明兑换后的货币可以一直增加,否则不能实现通过货币转 ...

  4. POJ1860 Currency Exchange(bellman-ford)

    链接:http://poj.org/problem?id=1860 Currency Exchange Description Several currency exchange points are ...

  5. ACM/ICPC 之 SPFA-兑换货币(POJ1860)

    //水题-SPFA解法 //套汇是指兑换货币后能使本金上升 //给定本金货币编号,货币间的汇率和手续费,求能否套汇成功 //Time:16Ms Memory:200K #include<iost ...

  6. [poj1860] Currency Exchange (bellman-ford算法)

    题目链接:http://poj.org/problem?id=1860 题目大意:给你一些兑换方式,问你能否通过换钱来赚钱? 使用ford算法,当出现赚钱的时候就返回YES,如果不能赚钱,则返回NO ...

  7. poj1860 bellman—ford队列优化 Currency Exchange

    Currency Exchange Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 22123   Accepted: 799 ...

  8. POJ1860 Currency Exchange(最短路)

    题目链接. 分析: 以前没做出来,今天看了一遍题竟然直接A了.出乎意料. 大意是这样,给定不同的金币的编号,以及他们之间的汇率.手续费,求有没有可能通过不断转换而盈利. 直接用Bellman-ford ...

  9. poj1860 解题报告

    题意:这里有N种货币,分别记为1~N,有M种货币交换的方式,每一种方式有A,B两种钱币,有RAB, CAB, RBA and CBA,四个数,表示交换率, Nick手上有其中的一种货币S,货币S的钱数 ...

  10. poj1860(spfa判正环)

    题目连接:http://poj.org/problem?id=1860 题意:有多种从a到b的汇率,在你汇钱的过程中还需要支付手续费,那么你所得的钱是 money=(nowmoney-手续费)*rat ...

随机推荐

  1. 物化视图SQL

    物化视图SQL,如果没有结果集,就证明数据库中不存在物化视图 select a.owner,'' column_name,a.table_name,b.segment_name,b.segment_t ...

  2. Python【每日一问】04

    问:a =  [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],求出列表a中所有奇数并构造新列表 答: 利用列表的元素下标遍历列表 a = [1, 2, 3, 4, 5, 6, 7, 8 ...

  3. Python【每日一问】03

    问:请给出下列代码的执行结果,并解释 a = dict.fromkeys([6, 7, 8], ["testing", {"name": "ken&q ...

  4. WindowsServer2012R2开机进入CMD,关闭后黑屏问题

    原因分析: 因为自己在卸载IIS的时候,不小心卸载了.net framework,系统没有了图形界面(由完整模式Full变为了核心模式core),需要重新恢复.net framework4.5. 解决 ...

  5. KPPW2.5 漏洞利用--CSRF

    kppw2.5 CSRF漏洞复现 漏洞说明 http://192.168.50.157/kppw25/index.php?do=user&view=message&op=send 收件 ...

  6. JAVA 异常类型结构分析

    JAVA 异常类型结构分析 Throwable 是所有异常类型的基类,Throwable 下一层分为两个分支,Error 和 Exception. Error 和 Exception Error Er ...

  7. Vue 父组件方法和参数传给子组件的方法

    <template> <div class="content-item"> <!-- openWnd是父组件自身的方法,openDutyWnd是子组件 ...

  8. python3 互译无线短信接口

    #!/usr/local/bin/python#-*- coding:utf-8 -*-import http.clientimport urllibimport random host = &quo ...

  9. centos7安装mysql客户端

    1.判断是否已安装 [root@k8s-master master]# which mysql /usr/bin/which: no mysql in (/usr/local/sbin:/usr/lo ...

  10. PHP对接微信支付采坑

    第一次做PHP商城项目对接微信支付接口,踩了N次坑,这也不对,那也不对,搞了很久,查了一些资料,终于实现了支付功能,小小总结一下,万一下次遇到就不用到处找资料了. 微信扫码支付 前期准备: 1.微信公 ...