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. 吐槽:那些Java设计中不得不说的槽点

    1. 求长度各有千秋 你是否曾经在面试的时候,经常被问到:数组有没有 length() 方法?字符串有没有 length() 方法? 集合有没有 length() 方法? 面对这个问题,那么不得不吐槽 ...

  2. redis 是如何做持久化的

    Redis 是一个键值对数据库服务器.基于内存存储数据,它常被用做缓存数据库,用来替代 memcached.官网:https://redis.io/ 什么是持久化? 持久化,指将数据存储到可永久保存的 ...

  3. 浅说——状压DP

    第一次没认真听,没听懂.(有点难) 第二次才搞懂,主要位运算太烦了!!! 位运算基础知识: 名称 符号 规则 按位与 & 全一则一,否则为零 按位或 | 有一则一,否则为零 按位取反 ~ 是零 ...

  4. SQLServer性能优化之---数据库级日记监控

    上节回顾:https://www.cnblogs.com/dotnetcrazy/p/11029323.html 4.6.6.SQLServer监控 脚本示意:https://github.com/l ...

  5. C# 6 新语法

    1. using 声明的静态用法 2. 表达式体方法 3. 表达式体属性 4. 自动实现的属性初始化器 5. 只读的自动属性 6. nameof 运算符 7. 空值传播运算符 8. 字符串插值 9. ...

  6. 如何正确使用Profibus插头以及终端电阻

    插头与终端电阻在Profibus通讯中有着非常重要的作用,它们使用起来非常简单,没有很多复杂的设置:但是正是由于使用简单,使得很多工程师在使用当中忽略了一些细节,导致很多通讯问题. 1 Profibu ...

  7. kuangbin专题 专题一 简单搜索 棋盘问题 POJ - 1321

    题目链接:https://vjudge.net/problem/POJ-1321 题意:给一张棋盘,‘#’表示可以下棋的地方,‘.’表示不能下棋的地方.棋盘是n*n的,要求能放下k个棋子,要求k个棋子 ...

  8. k8s学习 - 概念 - master/node

    k8s学习 - 概念 - master/node 在k8s中,有各种各样的概念和术语.这些概念是必须要学习和掌握的.我们先罗列下所有概念,然后再一个个看具体实例. 大概说一下这些概念: Master: ...

  9. dockerfile 制作镜像

    # Set the base image to UbuntuFROM ubuntu # File Author chenghanMAINTAINER chenghan ################ ...

  10. [原创]lvs+ospf+nginx实现高可用大流量web架构

    lvs+ospf+nginx实现高可用大流量web架构配置总概述 架构图: 配置如下: .quagga之zebra配置: # cat /etc/quagga/zebra.conf ! ! Zebra ...