题目链接: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. AdapterView及其子类之二:使用ListActivity及ArrayAdapter创建列表

    见归档项目ListActivityDemo.zip. 基本步骤如下: 1.创建一个TextView,用于指定每一个ListView的格式 <?xml version="1.0" ...

  2. SQLite使用教程6 创建表

    http://www.runoob.com/sqlite/sqlite-create-table.html SQLite 创建表 SQLite 的 CREATE TABLE 语句用于在任何给定的数据库 ...

  3. mysql slow log分析工具的比较

    mysql 中的 slow log 是用来记录执行时间较长(超过 long_query_time 秒)的 sql 的一种日志工具. 启用 slow log 在 my.cnf 中设置 [mysqld] ...

  4. 【25】考虑写出一个不抛异常的swap函数

    1.swap交换对象值,std提供了实现方法模版的实现,它的实现是交换对象值. namespace std { template<typename T> void swap(T& ...

  5. 应用之星推出“图文app”制作工具,并附上教程

    应用之星已推出的"图文"app制作工具,是高速制作图文电子书,图文杂志等一切有关图文资料的app生成工具,以下跟大家介绍"图文"制作教程,简单快捷,大致分三大步 ...

  6. android131 360 03 输入密码

    package com.itheima52.mobilesafe.activity; import android.app.Activity; import android.app.AlertDial ...

  7. 学习笔记之Python

    http://baike.baidu.com/view/21087.htm?fr=aladdin#reference-[12]-21087-wrap Python 基础教程(http://www.w3 ...

  8. PHP中的可变参数函数和可选参数函数

    1)可选参数函数.例如: <?phpfunction add($var1,$var2,$var3=0,$var4=0){ return$var1+$var2+$var3+$var4;}echo ...

  9. Android(java)学习笔记127:Android Studio新建工程中的build.gradle、settings.gradle

    随着信息化的快速发展,IT项目变得越来越复杂,通常都是由多个子系统共同协作完成.对于这种多系统.多项目的情况,很多构建工具都已经提供了不错的支持,像maven.ant.Gradle除了借鉴了ant或者 ...

  10. c++与c不太相同的一些地方2

    1.一般全局变量放到cpp 文件里面,而不是.h 里面.要不然容易乱套,这个乱几次就好了,先记住这样一种编码规范. 以为大家都引入就比较麻烦,但是实现起来就只有cpp里面才有.毕竟.h是要被包含的文件 ...