当前位置:网站首页>Poj1860 currency exchange solution
Poj1860 currency exchange solution
2022-07-28 13:49:00 【bj_ hacker】
POJ1860 Currency exchange solution
subject
link
http://poj.org/problem?id=1860
Literal description
Currency Exchange
Time Limit: 1000MS Memory Limit: 30000K
Total Submissions: 52661 Accepted: 20631
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
Source
Northeastern Europe 2001, Northern Subregion
Ideas
use Bellman-ford Judge whether there is a positive ring , That is to say n-1 After secondary relaxation , If you can relax again, there is a positive ring , Otherwise none .
Code implementation
#include<cstdio>
#include<string.h>
#include<cstring>
using namespace std;
const int maxn=1e4+10;
int n,m,s,cnt;
double v;
struct node{
int a,b;
double r,c;
}e[maxn];
double dis[maxn];
inline void add(int x,int y,double r,double c){
e[++cnt].a=x;
e[cnt].b=y;
e[cnt].r=r;
e[cnt].c=c;
}
inline bool Bellman_ford(){
memset(dis,0,sizeof(dis));
dis[s]=v;
for(int i=1;i<n;i++){
bool flag=false;
for(int j=1;j<=cnt;j++){
if(dis[e[j].b]<(dis[e[j].a]-e[j].c)*e[j].r){
dis[e[j].b]=(dis[e[j].a]-e[j].c)*e[j].r;
flag=true;
}
}
if(!flag)return false;
}
for(int i=1;i<=cnt;i++){
if(dis[e[i].b]<(dis[e[i].a]-e[i].c)*e[i].r)return true;
}
return false;
}
int main(){
scanf("%d%d%d%lf",&n,&m,&s,&v);
for(int i=1;i<=m;i++){
int x,y;
double a1,a2,b1,b2;
scanf("%d%d%lf%lf%lf%lf",&x,&y,&a1,&a2,&b1,&b2);
add(x,y,a1,a2);
add(y,x,b1,b2);
}
if(Bellman_ford())printf("YES\n");
else printf("NO\n");
return 0;
}
边栏推荐
- PHP generates random numbers (nickname random generator)
- Generation of tables and contingency tables (cross tables) of R language factor data: use the summary function to analyze the list, view the chi square test results, and judge whether the two factor v
- I miss the year of "losing" Li Ziqi
- How to play a data mining game entry Edition
- How to check if the interface cannot be adjusted? I didn't expect that the old bird of the 10-year test was planted on this interview question
- DXF读写:标注样式组码中文说明
- 倒计时 2 天!2022 中国算力大会:移动云邀您共见算力网络,创新发展
- Beyond Istio OSS——Istio服务网格的现状与未来
- R语言ggplot2可视化:可视化散点图并为散点图中的数据点添加文本标签、使用ggrepel包的geom_text_repel函数避免数据点标签互相重叠(自定义指定字体类型font family)
- word打字时后面的字会消失是什么原因?如何解决?
猜你喜欢

Half wave rectification light LED

word打字时后面的字会消失是什么原因?如何解决?

Children's programming electronic society graphical programming level examination scratch Level 2 real problem analysis (judgment question) June 2022

You have to apologize if you get involved in the funny shop?

Jar package

少儿编程 电子学会图形化编程等级考试Scratch二级真题解析(判断题)2022年6月

【ECMAScript6】Promise

Strict mode -- let and const -- arrow function -- Deconstruction assignment -- string template symbol -- set and map -- generator function

SAP UI5 FileUploader 控件实现本地文件上传,接收服务器端的响应时遇到跨域访问错误的试读版

30 day question brushing plan (II)
随机推荐
【C语言】结构体指针与结构体变量作形参的区别
R language uses dpois function to generate Poisson distribution density data and plot function to visualize Poisson distribution density data
Remember to use pdfbox once to parse PDF and obtain the key data of PDF
No swagger, what do I use?
Graph traversal (BFS & DFS basis)
朋友发来几个面试题
倒计时 2 天!2022 中国算力大会:移动云邀您共见算力网络,创新发展
Operator3-设计一个operator
Excellent performance! Oxford, Shanghai, AI Lab, Hong Kong University, Shangtang, and Tsinghua have joined forces to propose a language aware visual transformer for reference image segmentation! Open
R语言ggplot2可视化:使用ggpubr包的ggviolin函数可视化小提琴图、设置draw_quantiles参数添加指定分位数横线(例如,50%分位数、中位数)
剖析 kubernetes 集群内部 DNS 解析原理
算法---不同路径(Kotlin)
Using fail2ban to protect web servers from DDoS Attacks
Three men "running away" from high positions in the mobile phone factory
使用 IPtables 进行 DDoS 保护
POJ3259虫洞题解
数据库系统原理与应用教程(058)—— MySQL 练习题(二):单选题
[security] read rfc6749 and understand the authorization code mode under oauth2.0
Cesium pit -- pit used by various API calls and API itself
Map tiles: detailed explanation of vector tiles and grid tiles