设为首页 收藏本站
查看: 1004|回复: 0

[经验分享] POJ 1860

[复制链接]

尚未签到

发表于 2015-9-11 10:11:25 | 显示全部楼层 |阅读模式
Currency Exchange


Time Limit: 1000MS Memory Limit: 30000K
Total Submissions: 18899 Accepted: 6743

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
解释一下基本题意,SB—hypo有s货币,价&#20540;为V,他想获得很多其它的货币。身为一个妻管严,该怎么办?╮(╯▽╰)╭,无奈。。。货币交换公式 (B货币)  = (A货币总量-佣金)*汇率。
输入N,M,S,V;
以下M行,line 1 代表货币1 到 货币2 的 汇率、佣金,货币2 到 货币1 的 汇率、佣金
line 2 代表货币2 到 货币3 的 汇率、佣金,货币3 到 货币2 的 汇率、佣金


打印SB-hypo是否能添加收入?YES/NO
PS:  没什么难度。就是贝尔曼的模板,敲上就差点儿相同A了,可是WA了两次,以为是精度的问题,可是看了一下DISCUSS之后,发现dis[]的初始化不正确,应该为0,而不INF。由于这个题是逆向使用贝尔曼算法,找的不是负环。且没有负环。并代表就有正欢,仅仅能说明可能存在最短路,而是能够使之钱数无限添加的正环。


#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
const int INF = 1<<20;
const int N = 110;
const int Size = 9999;
using namespace std;
double mapp[N][N];
double dis[N],ANS;
int n,m,s,l;
double num;
struct node{
int u,v;
double hui,yong;
}edge[Size];
void init()
{
l = 0;//若是找负环,dis[]应该初始化INF
for(int i = 0;i<N;i++) //这里须要注意。由于找的是正环,初始化应该为0,可是不明确为什么不能为负
dis = 0;
}
int Bellamn()
{
int flag = 0;
for(int i = 0;i<n;i++)
{
flag = 0;
for(int j = 0;j<l;j++)
{     //曾经是 dis[edge[j].v] > dis[edge[j].u] + edge[j].w; 更新最短路
if(dis[edge[j].v] < (dis[edge[j].u] - edge[j].yong)* edge[j].hui) // 更新相对最长路
{
dis[edge[j].v] = (dis[edge[j].u] - edge[j].yong)* edge[j].hui;
flag = 1;
}
}
if(flag==0)//更新完成跳出
break;
}
for(int j = 0;j<l;j++)
{
if(dis[edge[j].v] < (dis[edge[j].u] - edge[j].yong)* edge[j].hui)//推断正环
{
return 1;
}
}
return 0;
}
int main()
{
int a,b;
double c,d,cc,dd;
while(~scanf(&quot;%d%d%d%lf&quot;,&n,&m,&s,&num))
{
init();
dis = num;
for(int i = 0;i<m;i++)
{
scanf(&quot;%d%d%lf%lf%lf%lf&quot;,&a,&b,&c,&d,&cc,&dd);
edge[l].u = a; edge[l].v = b; edge[l].hui = c; edge[l++].yong = d;
edge[l].u = b; edge[l].v = a; edge[l].hui = cc; edge[l++].yong = dd;
}
int st = Bellamn();
(st==1)?puts(&quot;YES&quot;):puts(&quot;NO&quot;);
}
return 0;
}



  








         
版权声明:本文博客原创文章,博客,未经同意,不得转载。

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.iyunv.com/thread-112211-1-1.html 上篇帖子: 发布App,赢iPad mini + 美金100$ 下篇帖子: PatentTips
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表