Several currency exchange points are working in our city. Let us suppose that each point specializes in two particular currencies and performs exchange operations only with these currencies. There can be several points specializing in the same pair of currencies. Each point has its own exchange rates, exchange rate of A to B is the quantity of B you get for 1A. Also each exchange point has some commission, the sum you have to pay for your exchange operation. Commission is always collected in source currency.
For example, if you want to exchange 100 US Dollars into Russian Rubles at the exchange point, where the exchange rate is 29.75, and the commission is 0.39 you will get (100 - 0.39) * 29.75 = 2963.3975RUR.

You surely know that there are N different currencies you can deal with in our city. Let us assign unique integer number from 1 to N to each currency. Then each exchange point can be described with 6 numbers: integer A and B - numbers of currencies it exchanges, and real R
AB, C
AB, R
BA and C
BA - exchange rates and commissions when exchanging A to B and B to A respectively.

Nick has some money in currency S and wonders if he can somehow, after some exchange operations, increase his capital. Of course, he wants to have his money in currency S in the end. Help him to answer this difficult question. Nick must always have non-negative sum of money while making his operations.

Input

The first line of the input contains four numbers: N - the number of currencies, M - the number of exchange points, S - the number of currency Nick has and V - the quantity of currency units he has. The following M lines contain 6 numbers each - the description of the corresponding exchange point - in specified above order. Numbers are separated by one or more spaces. 1<=S<=N<=100, 1<=M<=100, V is real number, 0<=V<=10
3.

For each point exchange rates and commissions are real, given with at most two digits after the decimal point, 10
-2<=rate<=10
2, 0<=commission<=10
2.

Let us call some sequence of the exchange operations simple if no exchange point is used more than once in this sequence. You may assume that ratio of the numeric values of the sums at the end and at the beginning of any simple sequence of the exchange operations will be less than 10
4.

Output

If Nick can increase his wealth, output YES, in other case output NO to the output file.

Sample Input

3 2 1 20.0
1 2 1.00 1.00 1.00 1.00
2 3 1.10 1.00 1.10 1.00

Sample Output

YES

题意:N种货币,M个兑换点,S开始的货币类型,V开始拥有的货币数
给出M个兑换点的信息
a b 代表兑换的两种货币,然后给出a兑换b的汇率和佣金,b兑换a的汇率和佣金
问是否可以经过多轮兑换后使得本金变多 思路:spfa判断正环
两种方法 cnt【y】++ ,直到cnt【y】 >= n (y代表放入队列的点,也就是松弛点)
    cnt【y】+=cnt【x】,直到cnt【y】>=n
当然这题也可以判断dist【v】 > V?(表示起点)
 #include<cstdio>
#include<cstring>
#include<queue> using namespace std; int n,m,s;
double v; struct Node
{
int y;
double val;
double sub;
int next;
Node(int y=,double val=,double sub = ,int next=):y(y),val(val),sub(sub),next(next) {}
} node[]; int cnt,head[];
void add(int x,int y,double val,double sub)
{
node[++cnt].y=y;
node[cnt].next=head[x];
node[cnt].val=val;
node[cnt].sub=sub;
head[x]=cnt;
}
queue<int>que;
double dist[];
int vis[];
int tot[];
int num[];
bool spfa()
{
while(!que.empty())que.pop();
memset(vis,,sizeof(vis));
memset(dist,,sizeof(dist));
memset(num,,sizeof(num));
que.push(s);
dist[s] = v;
while(!que.empty())
{ int from = que.front();
que.pop();
vis[from] = ;
for(int i=head[from]; i; i=node[i].next)
{
int to = node[i].y;
if(dist[to] < (dist[from]-node[i].sub)*node[i].val)
{
dist[to] = (dist[from]-node[i].sub)*node[i].val;
if(!vis[to])
{
que.push(to);
vis[to]=;
num[to]++;
if(num[to]>= n)return ;
}
}
}
// if(dist[s] > v)return 1;
}
return ;
} int main()
{
scanf("%d%d%d%lf",&n,&m,&s,&v);
for(int i=; i<=m; i++)
{
int u,v;
double a,b,c,d;
scanf("%d%d",&u,&v);
scanf("%lf%lf%lf%lf",&a,&b,&c,&d);
add(u,v,a,b);
add(v,u,c,d);
}
int ans = spfa();
if(ans)printf("YES\n");
else printf("NO\n");
}
												

Currency Exchange POJ - 1860 (spfa判断正环)的更多相关文章

  1. Currency Exchange POJ - 1860 spfa判断正环

    //spfa 判断正环 #include<iostream> #include<queue> #include<cstring> using namespace s ...

  2. Currency Exchange POJ - 1860 (spfa)

    题目链接:Currency Exchange 题意: 钱的种类为N,M条命令,拥有种类为S这类钱的数目为V,命令为将a换成b,剩下的四个数为a对b的汇率和a换成b的税,b对a的汇率和b换成a的税,公式 ...

  3. poj 1860 (Bellman_Ford判断正环)

    题意:给出n种货币,m中交换关系,给出两种货币汇率和手续费,求能不能通过货币间的兑换使财富增加. 用Bellman_Ford 求出是否有正环,如果有的话就可以无限水松弛,财富可以无限增加. #incl ...

  4. poj1860 Currency Exchange(spfa判断正环)

    Description Several currency exchange points are working in our city. Let us suppose that each point ...

  5. poj3621 SPFA判断正环+二分答案

    Farmer John has decided to reward his cows for their hard work by taking them on a tour of the big c ...

  6. (最短路 SPFA)Currency Exchange -- poj -- 1860

    链接: http://poj.org/problem?id=1860 Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 2326 ...

  7. HDU 1317(Floyd判断连通性+spfa判断正环)

    XYZZY Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  8. HDU 1317XYZZY spfa+判断正环+链式前向星(感觉不对,但能A)

    XYZZY Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Subm ...

  9. Currency Exchange 货币兑换 Bellman-Ford SPFA 判正权回路

    Description Several currency exchange points are working in our city. Let us suppose that each point ...

随机推荐

  1. flask websocker

    WebSocket 是一种网络通信协议.RFC6455 定义了它的通信标准. HTTP 协议是一种无状态的.无连接的.单向的应用层协议.它采用了请求/响应模型.通信请求只能由客户端发起,服务端对请求做 ...

  2. c编译动态库可以编译但是无法导入解决方法

    $(CC) $(CFLAGS) -Wl,--whole-archive ${libusb} -Wl,--no-whole-archive $(lib_objs) $(LFLAGS) -o $(lib) ...

  3. OCC上下文设置显示模式

    #include <AIS_InteractiveContext.hxx> 通过AIS_InteractiveContext::SetDisplayMode()函数来设置 void  Se ...

  4. Spring Cloud微服务实践之路-起始

    由于各种原因,公司要对现有的营销产品进行微服务化,如果可以,则对公司所有产品逐步进行微服务化. 而本人将探索这条路,很艰难,但干劲十足.整个过会记录下来,以便以后查阅. 感谢公司!感谢领导! 相关书籍 ...

  5. Anniversary party POJ - 2342 (树形DP)

    题目链接:  POJ - 2342 题目大意:给你n个人,然后每个人的重要性,以及两个人之间的附属关系,当上属选择的时候,他的下属不能选择,只要是两个人不互相冲突即可.然后问你以最高领导为起始点的关系 ...

  6. Android O广播接收情况

    target-261.卸载和清除收据(这两个在例外广播列表中) 可以收到广播2.应用商店升级app 收不到android.intent.action.PACKAGE_REPLACED广播,应用自身可以 ...

  7. 分布式系列九: kafka

    分布式系列九: kafka概念 官网上的介绍是kafka是apache的一种分布式流处理平台. 最初由Linkedin开发, 使用Scala编写. 具有高性能,高吞吐量的特定. 包含三个关键能力: 发 ...

  8. 「JavaScript面向对象编程指南」基础

    DOM标准是独立的(即并不依赖JS)操作结构化文档的方式 BOM实际是个与浏览器有关的对象集合,原来没任何标准可言,H5诞生后才被定义了一些浏览器间通用的对象标准 ES5严格模式"use s ...

  9. Arduino语言简介

    参考链接:https://www.cnblogs.com/xczr/p/7831343.html

  10. 前端笔记知识点整合之JavaScript(二)关于运算符&初识条件判断语句

    运算符 数学运算符的正统,number和number的数学运算,结果是number.出于面试的考虑,有一些奇奇怪怪的数学运算: 数学运算中:只有纯字符串.布尔值.null能够进行隐式转换.   //隐 ...