Description

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 RAB, CAB, RBA and CBA - 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<=103
For each point exchange rates and commissions are real, given with at most two digits after the decimal point, 10-2<=rate<=102, 0<=commission<=102
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 104

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

题意:

大概就是换钱,交换点是1~N,每个点都能把相应的钱转换为另一种,(本金-手续费)*汇率=转换后所得的钱。

问你能不能让他的钱变多。

思路:

要自闭了,这么难的英文,看半天都看不懂。。。。。N,M,S,V:分别代表N个交换点,m种转换方式,S是初始的货币种类(即与源点),V是拥有的S类货币数量,每行输入 A、B、RAB、CAB、RBA、CBA 分别为A、B两种货币,A换成B的汇率以及手续费,B换成A的汇率以及手续费。把题看为求源点到其他点的最短路径即可,用Bellman-ford判断是否有正环即可(因为是想让钱那边多)。

代码:

#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <limits>
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define Sci(x) scanf("%d",&x)
#define Sci2(x, y) scanf("%d%d",&x,&y)
#define Sci3(x, y, z) scanf("%d%d%d",&x,&y,&z)
#define Scl(x) scanf("%I64d",&x)
#define Scl2(x, y) scanf("%I64d%I64d",&x,&y)
#define Scl3(x, y, z) scanf("%I64d%I64d%I64d",&x,&y,&z)
#define Pri(x) printf("%d\n",x)
#define Prl(x) printf("%I64d\n",x)
#define For(i,x,y) for(int i=x;i<y;i++)
#define FFor(i,x,y) for(int i=x;i>y;i--)
#define For_(i,x,y) for(int i=x;i<=y;i++)
#define FFor_(i,x,y) for(int i=x;i>=y;i--)
#define Mem(f, x) memset(f,x,sizeof(f))
#define LL long long
#define ULL unsigned long long
#define MAXSIZE 255
#define INF 0x3f3f3f3f
const int mod = 1e9+;
const double PI = acos(-1.0); using namespace std;
struct node
{
int s;
int e;
double r;
double c;
} edge[MAXSIZE];
double dis[MAXSIZE];//dis[i]表示当货币种类为i时钱的数目
int n,m,s;
double v;//钟类,交换点 哪个 多少钱,
void bellman(int k)
{
Mem(dis,);//这个地方初始化为0,因为要判断是否有正环
dis[s]=v;//源点距离为v即他最开始拥有的钱
For(i,,n)
For(j,,k)
{
node data=edge[j];
if(dis[data.e]<(dis[data.s]-data.c)*data.r)//此处用的小于号,松弛找到做多的钱
dis[data.e]=(dis[data.s]-data.c)*data.r;
}
For(i,,k)
{
node data=edge[i];
if(dis[data.e]<(dis[data.s]-data.c)*data.r )//说明有正环
{
printf("YES\n");
return ;
}
}
printf("NO\n");
}
int main()
{
// int x,y,z;
//if(dis[edge[i].e]<dis[edge[]])
//scanf("%d%d%d%d",)
Sci3(n,m,s);
scanf("%lf",&v);
int s,e;
int k=;
while(m--)
{
Sci2(s,e);
edge[k].s=s;
edge[k].e=e;
scanf("%lf%lf",&edge[k].r,&edge[k].c);
k++;
edge[k].s=e;
edge[k].e=s;
scanf("%lf%lf",&edge[k].r,&edge[k].c);
k++;
}
bellman(k);
return ;
}

Currency Exchange POJ1860的更多相关文章

  1. Bellman_ford 算法 Currency Exchange POJ1860

    Bellman_ford算法用于寻找正环或者负环! 算法导论: 24.1 The Bellman-Ford algorithm The Bellman-Ford algorithm solves th ...

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

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

  3. POJ1860 Currency Exchange(bellman-ford)

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

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

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

  5. POJ1860 Currency Exchange【最短路-判断环】

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

  6. POJ1860:Currency Exchange(BF)

    http://poj.org/problem?id=1860 Description Several currency exchange points are working in our city. ...

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

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

  8. POJ1860 Currency Exchange —— spfa求正环

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

  9. POJ-1860 Currency Exchange( Bellman_Ford, 正环 )

    题目链接:http://poj.org/problem?id=1860 Description Several currency exchange points are working in our ...

随机推荐

  1. 使用MVVM的常见误区(1)在ViewModel中和用户交互

    缺点,不能进行单元测试 比如,用户在界面点击按钮,实现用户选择一个文件,然后对文件内容进行解析.常见错误如下 using Microsoft.Win32; namespace View和ViewMod ...

  2. JavaScript 词法作用域不完全指北

    在 JavaScript 作用域不完全指北 中,我们介绍了作用域的概念以及 JavaScript 引擎.编译器和作用域的关系.作用域有两种主要的工作模型:词法作用域和动态作用域.其中最为普遍的也是大多 ...

  3. 设计模式-访问者模式(Visitor)

    访问者模式是行为模式的一种.访问者模式的基本想法是,软件系统中拥有一个由许多对象构成的.比较稳定的对象结构,这些对象的类都拥有一个accept方法用来接受访问者的访问.访问者是一个接口,它拥有一个vi ...

  4. HDU 3062:Party(2-SAT入门)

    http://acm.hdu.edu.cn/showproblem.php?pid=3062 题意:中文. 思路:裸的2-SAT.判断二元组的两个人是否在同一个强连通分量. 学习地址:http://w ...

  5. Linux中修改远程地址

    首先跳转到本地用户root,如果不是的话可能没有权限 第一步:安装ssh服务 执行命令:yum install openssh-server (因为我已经安装过了,所以显示的是已安装) 第二步:修改S ...

  6. Java基础之回味finally

    平时大家try…catch…finally语句用的不少,知道finally块一定会在try…catch..执行结束时执行,但是具体是在什么时候执行呢,今天我们一起来看下. public static ...

  7. 手机如何进入开发者选项--以vivo为例

    发现一个新方法  打开拨号键盘        输入    *#*#7777#*#* 欧儿了

  8. 剑指offer第二版-6.从尾到头打印链表

    描述:输入一个链表的头节点,从尾到头打印每个节点的值. 思路:从尾到头打印,即为“先进后出”,则可以使用栈来处理:考虑递归的本质也是一个栈结构,可递归输出. 考点:对链表.栈.递归的理解. packa ...

  9. Centos7.4 的yum源库配置。

    http://mirrors.163.com/.help/centos.html https://www.cnblogs.com/mchina/archive/2013/01/04/2842275.h ...

  10. Junit简单的案例

    Calculator: public class Calculator { public double add(double number1, double number2) { return num ...