Currency Exchange(最短路)
| Time Limit: 1000MS | Memory Limit: 30000K | |
| Total Submissions: 29851 | Accepted: 11245 |
Description
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
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
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 题目大意:
题目中主要是说存在货币兑换点,然后现在手里有一种货币,要各种换来换去,最后再换回去的时候看能不能使原本的钱数增多,每一种货币都有对应的汇率,而货币A到货币B的汇率即为1货币A换得得货币B的数量,但兑换点是要收取佣金的,且佣金从源货币中扣除,例如,你想在汇率29.75,佣金为0.39的兑换点把100美元换成卢布,得到的卢布数即为(100-0.39)*29.75 = 2963.3975.
样例解释:
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
多组输入,第一行中N代表有N种货币可以互相兑换,M代表有M个货币兑换点,S代表这个人手中的的货币的编号,V代表这个人手中拥有的货币数量,底下M行
每行六个数,A,B代表可以交换的货币A和B,剩下的实数RAB,CAB,RBA,CBA,代表A到B的汇率,佣金,B到A的汇率,佣金。以某种兑换方式增加原本的钱数,而且必须兑换为原来的货币。
#include<queue>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define N 1010
using namespace std;
int n,m,head[N],sum[N],tot,num,u,v;
bool vis[N];
double dis[N],x,y,xx,yy,money;
struct Edge
{
int u,v,next;
double x,y;
}edge[N<<];
int add(int u,int v,double x,double y)//注意:传上来的是double类型的,开始时一直传的是int导致wa
{
tot++;//从1开始用,开始时一直是在后面++,导致一直wa
edge[tot].u=u;
edge[tot].v=v;
edge[tot].x=x;
edge[tot].y=y;
edge[tot].next=head[u];
head[u]=tot;
}
void begin()
{
memset(head,,sizeof(head));
memset(sum,,sizeof(sum));
memset(dis,,sizeof(dis));
memset(vis,false,sizeof(vis));
tot=;
}
int spfa(int s)
{
queue<int>q;
dis[s]=money;
vis[s]=true;
q.push(s);
while(!q.empty())
{
int x=q.front();
q.pop();vis[x]=false;
for(int i=head[x];i;i=edge[i].next)
{
int v=edge[i].v;
if(dis[v]<(dis[x]-edge[i].y)*edge[i].x)
{
dis[v]=(dis[x]-edge[i].y)*edge[i].x;
if(!vis[v])
{
vis[v]=true;
q.push(v);
}
sum[v]++;
if(sum[v]>n)
;
}
}
}
;
}
int main()
{
while(scanf("%d %d %d %lf",&n,&m,&num,&money)!=EOF)
{
begin();
;i<=m;i++)
{
scanf("%d %d %lf %lf %lf %lf",&u,&v,&x,&y,&xx,&yy);
add(u,v,x,y);
add(v,u,xx,yy);
}
) printf("NO\n");
else printf("YES\n");
}
;
}
Currency Exchange(最短路)的更多相关文章
- POJ 1860 Currency Exchange 最短路+负环
原题链接:http://poj.org/problem?id=1860 Currency Exchange Time Limit: 1000MS Memory Limit: 30000K Tota ...
- POJ 1860 Currency Exchange (最短路)
Currency Exchange Time Limit:1000MS Memory Limit:30000KB 64bit IO Format:%I64d & %I64u S ...
- poj 1860 Currency Exchange (最短路bellman_ford思想找正权环 最长路)
感觉最短路好神奇呀,刚开始我都 没想到用最短路 题目:http://poj.org/problem?id=1860 题意:有多种从a到b的汇率,在你汇钱的过程中还需要支付手续费,那么你所得的钱是 mo ...
- POJ 1860 Currency Exchange 最短路 难度:0
http://poj.org/problem?id=1860 #include <cstdio> //#include <queue> //#include <deque ...
- POJ1860 Currency Exchange(最短路)
题目链接. 分析: 以前没做出来,今天看了一遍题竟然直接A了.出乎意料. 大意是这样,给定不同的金币的编号,以及他们之间的汇率.手续费,求有没有可能通过不断转换而盈利. 直接用Bellman-ford ...
- 最短路(Bellman_Ford) POJ 1860 Currency Exchange
题目传送门 /* 最短路(Bellman_Ford):求负环的思路,但是反过来用,即找正环 详细解释:http://blog.csdn.net/lyy289065406/article/details ...
- POJ 1860 Currency Exchange (最短路)
Currency Exchange Time Limit : 2000/1000ms (Java/Other) Memory Limit : 60000/30000K (Java/Other) T ...
- POJ1860——Currency Exchange(BellmanFord算法求最短路)
Currency Exchange DescriptionSeveral currency exchange points are working in our city. Let us suppos ...
- POJ1860 Currency Exchange【最短路-判断环】
Several currency exchange points are working in our city. Let us suppose that each point specializes ...
- (最短路 SPFA)Currency Exchange -- poj -- 1860
链接: http://poj.org/problem?id=1860 Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 2326 ...
随机推荐
- win7旗舰版下配置IIS服务器
选择上述的插件后,Windows 需要更新一段时间,并重启电脑 测试是否安装成功:http://localhost 注意:默认端口号是 80,不能和tomcat 的 80 端口同时重启 常 ...
- shell脚本,一个shell的启动流程。
#一个shell的启动流程 #shell有一些变量,叫做环境变量,这些变量是可以继承的, #比如父shell有$UID,子shell也可以有,而且继承父shell的. #正常我们声明一个变量,a=,在 ...
- iOS之WKWebView
Xcode8发布以后,编译器开始不支持IOS7,所以很多应用在适配IOS10之后都不在适配IOS7了,其中包括了很多大公司,网易新闻,滴滴出行等.因此,我们公司的应用也打算淘汰IOS7. 支持到IOS ...
- jwt 登录
/* eslint-disable */ 'use strict'; const Controller = require('egg').Controller; const jwt = require ...
- 开启和连接mysql服务器(win10为例)
1.windows图标右键,选择“计算机管理”: 2.展开左边的“ 服务和应用程序” 选项,点击“服务",找到 MySQL 服务器,点击左侧的 "启动",即可完成 MyS ...
- 译文 编写一个loader
https://doc.webpack-china.org/contribute/writing-a-loader loader是一个导出了函数的node模块,当资源须要被这个loader所转换的时候 ...
- C语言之链接库
链接库是windows的术语,但对于Linux来说,其概念是一样的.我们通常会把一些相似或相近功能的程序生成链接库,这样的好处是: 1)便于共享,开发软件时如需要相同功能时,不需要将大量重复的代码整合 ...
- rom bist scripts
rom bist 的input 有rom_content file .校验rom还坏,主要通过signature比较.signature跟rom content file 一一对应的. rom bis ...
- perl学习之:肯定匹配和否定匹配
tr/ / / 替换操作符不支持正则表达式 也不具备双引号替换能力m/ / s/ / / 都支持正则表达式,并且可以提供或限制双引号替换能力 $string = "25abc8" ...
- 常用模块之configpaser与shutil
configparser模块 定义:configparser翻译为配置解析,即它是用来解析配置文件的 配置文件:用于编写程序的配置信息的文件 配置文件编写格式 配置文件中只允许出现两种类型的数据 se ...