题目链接: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. ZOJ1111:Poker Hands(模拟题)

    A poker deck contains 52 cards - each card has a suit which is one of clubs, diamonds, hearts, or sp ...

  2. 可学习的多人人脸识别程序(基于Emgu CV)

    源代码下载(需要安装Emgu CV,安装方法请百度) 很多朋友使用Emgu CV遇到CvInvoke()的报错,我找到一种解决方法. 把EmguCV目录下bin里面的所有dll复制到C:\WINDOW ...

  3. Abel 分部求和法

    本文之所以叫Abel分部求和法而不叫Abel分部求和公式,是因为求和公式有可能形式上有所不同,但是方法确实相同的. $$\sum_{n=M}^{N}a_{n}b_{n} = \sum_{n=M}^{N ...

  4. 人工智能-有限状态机(FSM)的学习

    首先声明:此文源于本人最近学习的一本书 <游戏人工智能编程案例精粹> FSM的定义: 一个有限状态机是一个设备,或是一个设备模型,具有有限数量的状态,它可以在任何给定的时间根据输入进行操作 ...

  5. Vim文本编辑器 指令簿(二)

    常常处理文本以及常常须要写代码的人,都会有自己比較常常使用的编辑器,本人喜欢用Vim.理由就是Vim编辑器灵活,而且能够达到纯键盘操作,使用纯熟情况下,根本不须要鼠标操作.听起来是不是非常酷的?只是别 ...

  6. Android TabHost TabWidget 去除黑线(底部下划线)

    采用TabHost布局时,往往会发现默认的系统风格与软件风格很不协调,比如TabWidget的下划线影响布局效果.通常情况下会去除其下划线.如果是采用xml布局文件,在TabWidget的属性项设置a ...

  7. 详解 MySQL 中的 explain

    来源:persister 链接:http://www.blogjava.net/persister/archive/2008/10/27/236813.html 在 explain的帮助下,您就知道什 ...

  8. 关于Android模拟器键盘不能使用的解决方法

    很多朋友遇到一个问题,自己搭建完了Android环境后,启动模拟器体验Android系统,但是发现不能使用键盘方便的输入内容,如下图: 同时,使用笔记本的键盘也无法输入内容,只能通过模拟器内置的输入法 ...

  9. IBM Rational ClearCase 部署指南

    引言 随着时间的推移,可视化设计与软件配置管理(SCM)已经逐渐成为现代软件项目成功的关键因素.IBM Rational 是 IBM Rational XDE 和 IBM Rational Clear ...

  10. (一)javascript中的数组index属性——获取数组的索引值

    例如:要做到这样的效果 点击每个选项时,会显示不同的div. 我们的做法:在javascript中,先把所有的div的display设置为none,然后在根据当前的数组里的索引值进行一个显示div的过 ...