题目链接:http://poj.org/problem?id=1860

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 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 ( - 0.39) * 29.75 = .3975RUR.
You surely know that there are N different currencies you can deal with in our city. Let us assign unique integer number from to N to each currency. Then each exchange point can be described with 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 numbers each - the description of the corresponding exchange point - in specified above order. Numbers are separated by one or more spaces. <=S<=N<=, <=M<=, V is real number, <=V<=.
For each point exchange rates and commissions are real, given with at most two digits after the decimal point, -<=rate<=, <=commission<=.
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 .
Output If Nick can increase his wealth, output YES, in other case output NO to the output file.
Sample Input 20.0
1.00 1.00 1.00 1.00
1.10 1.00 1.10 1.00
Sample Output YES

题意:有N种货币 每两种货币之间有汇率和佣金 问是否能通过转换钱币使原来的钱数增加

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <math.h>
#include <vector>
using namespace std;
#define N 1010
#define ll long long
#define INF 0x3f3f3f3f
#define met(a,b) memset(a,b,sizeof(a));
vector<vector<int> >Q;
struct node
{
int v,next;
double vl,va;
}Map[N];
int s[N],k,vis[N],num[N];
double dis[N],vl;
int n,m,p;
void add(int u,int v,double vl,double va)
{
Map[k].v=v;
Map[k].next=s[u];
Map[k].vl=vl;
Map[k].va=va;
s[u]=k++;
}
int spfa()
{
met(vis,);met(num,);met(dis,);
queue<int>Q;
Q.push(p);
vis[p]=;
dis[p]=vl;
num[p]++;
while(Q.size())
{
int u=Q.front();
Q.pop();
vis[u]=;
for(int i=s[u];i!=-;i=Map[i].next)
{
int v=Map[i].v;
if(dis[v]<(dis[u]-Map[i].va)*Map[i].vl)
{
dis[v]=(dis[u]-Map[i].va)*Map[i].vl;
if(!vis[v])
{
Q.push(v);
vis[v]=;
num[v]++;
if(num[u]>n)
return ;
}
} } }
if(dis[p]>vl)
return ;
return ;
}
int main()
{
int a,b;
double v1,v2,v3,v4;
while(scanf("%d %d %d %lf",&n,&m,&p,&vl)!=EOF)
{
met(s,-);
k=;
for(int i=;i<m;i++)
{
scanf("%d %d %lf %lf %lf %lf",&a,&b,&v1,&v2,&v3,&v4);
add(a,b,v1,v2);
add(b,a,v3,v4);
}
if(spfa())
printf("YES\n");
else
printf("NO\n");
}
return ;
}

(poj)1806 Currency Exchange的更多相关文章

  1. RabbitMQ学习系列(四): 几种Exchange 模式

    上一篇,讲了RabbitMQ的具体用法,可以看看这篇文章:RabbitMQ学习系列(三): C# 如何使用 RabbitMQ.今天说些理论的东西,Exchange 的几种模式. AMQP协议中的核心思 ...

  2. RabbitMQ系列(三)RabbitMQ交换器Exchange介绍与实践

    RabbitMQ交换器Exchange介绍与实践 RabbitMQ系列文章 RabbitMQ在Ubuntu上的环境搭建 深入了解RabbitMQ工作原理及简单使用 RabbitMQ交换器Exchang ...

  3. POJ 1860:Currency Exchange

    Currency Exchange Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 22648   Accepted: 818 ...

  4. (poj)3159 Candies

    题目链接:http://poj.org/problem?id=3159 Description During the kindergarten days, flymouse was the monit ...

  5. 【POJ】1860 Currency Exchange

    真是气skr人..没把d[]换成double...de了一上午的bug// 记得用G++提交啊 题目链接:http://poj.org/problem?id=1860 题意:告诉你n个点,m条路.起始 ...

  6. (3)RabbitMQ交换器(Exchange)

    1.前言 上个章节也有简单介绍过RabbitMQ交换器,这里主要了解下它的类型和如何使用.交换器有四种类型,分别是direct.fanout.topic.headers. 2.Virtual host ...

  7. (poj)1502 MPI Maelstrom

    题目链接:http://poj.org/problem?id=1502 Description BIT has recently taken delivery of their processor A ...

  8. (poj)3268 Silver Cow Party 最短路

    Description One cow ≤ N ≤ ) conveniently numbered ..N ≤ X ≤ N). A total of M ( ≤ M ≤ ,) unidirection ...

  9. (poj)3020 Antenna Placement 匹配

    题目链接 : http://poj.org/problem?id=3020 Description The Global Aerial Research Centre has been allotte ...

随机推荐

  1. ASP.NET MVC- EF基础

    EF是在ADO.NET的基础上做进一步封装,以后如果做新的项目我可能会考虑不用ADO.NET,而用EF. 其实很久以前我就接触过EF,可是太久没用,有些忘记了,前几天重温,也做了一点笔记.记录如下: ...

  2. 【C++深入浅出】设计模式学习之观察者模式

    前言 前两天学习了weak_ptr以后还是不甚明了,一则需要实际应用去锤炼,二来就是不懂观察者模式. 正文 观察者模式又叫发布-订阅模式,定义了一种一对多的依赖关系,让多个观察者对象同时监听某一主题对 ...

  3. xcode6.4 7.2下载地址

    XCode 7.2 :ht tp://adcdownload.apple.com/Developer_Tools/Xcode_7.2/Xcode_7.2.dmgXCode7.1.1:ht tp://a ...

  4. TortoiseGit disconnected: no supported authentication methods available(server sent:publickey)

    之前一直用命令行,现在想用图形工具,TortoiseGit,安装后遇到错误 TortoiseGit disconnected: no supported authentication methods ...

  5. 并查集类的c++封装,比較union_find algorithm四种实现方法之间的性能区别

    问题描写叙述: 在计算机科学中,并查集是一种树型的数据结构,其保持着用于处理一些不相交集合(Disjoint Sets)的合并及查询问题.有一个联合-查找算法(union-find algorithm ...

  6. Eclipse 开发WEB项目所遇问题 WebContent WebRoot

    原文:http://blog.sina.com.cn/s/blog_525960510100jo0j.html 最近在做Web 项目时,新建了一个WEB 项目,如webdemo,eclipse默认的b ...

  7. [Heroku] How to pull, push changes

    1. First you need to login heroku: heroku login 2. Then you need to download the code: heroku git:cl ...

  8. SAP进销存难点分析及对策

    1.基本需求: 业务部门提出如上表格式进销存需求,并且金额要和总账中存货科目保持一致,如果要实现上表格式进校存,可以通过SAP标准程序(MC.9.MB51.MB5B)加工繁琐而成.现分析一下SAP标准 ...

  9. location查询字符串解析

    function getQueryStringArgs() { //取得查询字符串并去掉开头的问号 var qs = (location.search.length >0? location.s ...

  10. Zend Studio 10正式版注册破解

    1.文件和汉化文件 ZendStudio官方下载地址:http://www.geekso.com/component/zendstudio-downloads/ 百度云地址: 10.0.0.msi文件 ...