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. Programming In Lua 第十章

    1,lua中的数据结构都是表来实现的.数组就是索引为数值的表. 2,矩阵就是二维数组,三角矩阵就是矩阵的一半. 3,稀疏矩阵问题: 4, 5, 6,

  2. 从零开始实现ASP.NET Core MVC的插件式开发(二) - 如何创建项目模板

    标题:从零开始实现ASP.NET Core MVC的插件式开发(二) - 如何创建项目模板 作者:Lamond Lu 地址:https://www.cnblogs.com/lwqlun/p/11155 ...

  3. iOS 唤起APP之Universal Link(通用链接)

    什么是Universal Link(通用链接) Universal Link(通用链接)是Apple在iOS9推出的一种能够方便的通过传统HTTPS链接来启动APP的功能,可以使用相同的网址打开网址和 ...

  4. logging,包

    包 import 方式 所有对包的操作,都相当于对包下的__init__操作 from a.b.c import d b 必须 是包 import 最后只有一个层级 相对导入 . 代表当前路径, .. ...

  5. HDU XXXX:求[L,R]的素数数量(数位DP)

    Problem G Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 131072/131072K (Java/Other) Total S ...

  6. django基础知识之中间件:

    中间件 是一个轻量级.底层的插件系统,可以介入Django的请求和响应处理过程,修改Django的输入或输出 激活:添加到Django配置文件中的MIDDLEWARE_CLASSES元组中 每个中间件 ...

  7. Python线程池ThreadPoolExecutor源码分析

    在学习concurrent库时遇到了一些问题,后来搞清楚了,这里记录一下 先看个例子: import time from concurrent.futures import ThreadPoolExe ...

  8. ~~函数基础(七):生成器&迭代器~~

    进击のpython 生成器 上来说个这,就有点抽象了! 我们先整点活儿 宁,准备好了吗? 直接相位猛冲! 列表生成器 需求来了,老弟!我有一个数组 a = [1, 2, 3, 4, 5, 6, 7, ...

  9. redux、react-redux、redux-thunk、redux-saga使用及dva对比

    一.redux使用 Redux的核心概念其实很简单:将需要修改的state都存入到store里,发起一个action用来描述发生了什么,用reducers描述action如何改变state tree ...

  10. Excel催化剂开源第5波-任务窗格在OFFICE2013中新建文档不能同步显示问题解决

    在OFFICE2013及之后,使用了单文档界面技术,不同于以往版本可以共享任务空格.功能区.所以当开发任务窗格时,需要考虑到每一个工作薄都关联一个任务窗格. 背景介绍 单文档界面摘录官方定义如下:对 ...