Arbitrage
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 19063   Accepted: 8069

Description

Arbitrage is the use of discrepancies in currency exchange rates to transform one unit of a currency into more than one unit of the same currency. For example, suppose that 1 US Dollar buys 0.5 British pound, 1 British pound buys 10.0 French francs, and 1 French franc buys 0.21 US dollar. Then, by converting currencies, a clever trader can start with 1 US dollar and buy 0.5 * 10.0 * 0.21 = 1.05 US dollars, making a profit of 5 percent.

Your job is to write a program that takes a list of currency
exchange rates as input and then determines whether arbitrage is
possible or not.

Input

The
input will contain one or more test cases. Om the first line of each
test case there is an integer n (1<=n<=30), representing the
number of different currencies. The next n lines each contain the name
of one currency. Within a name no spaces will appear. The next line
contains one integer m, representing the length of the table to follow.
The last m lines each contain the name ci of a source currency, a real
number rij which represents the exchange rate from ci to cj and a name
cj of the destination currency. Exchanges which do not appear in the
table are impossible.

Test cases are separated from each other by a blank line. Input is terminated by a value of zero (0) for n.

Output

For
each test case, print one line telling whether arbitrage is possible or
not in the format "Case case: Yes" respectively "Case case: No".

Sample Input

3
USDollar
BritishPound
FrenchFranc
3
USDollar 0.5 BritishPound
BritishPound 10.0 FrenchFranc
FrenchFranc 0.21 USDollar 3
USDollar
BritishPound
FrenchFranc
6
USDollar 0.5 BritishPound
USDollar 4.9 FrenchFranc
BritishPound 10.0 FrenchFranc
BritishPound 1.99 USDollar
FrenchFranc 0.09 BritishPound
FrenchFranc 0.19 USDollar 0

Sample Output

Case 1: Yes
Case 2: No

思路:
抽象出来这题就是要求一个图的最大环,仍然用Floyd算法
要注意下G数组的对角线的值都要是1

#include <iostream>
#include <cstring>
#include <map>
using namespace std; map<string,int> money;
double G[][];
int n,m; void Floyd()
{
for(int k = ;k <= n;k++)
for(int i = ;i <= n;i++)
for(int j = ;j <= n;j++)
if(G[i][j] < G[i][k]*G[k][j])
G[i][j] = G[i][k]*G[k][j];
} int main()
{
int countt = ;
while(cin>>n && n)
{
string tmp;
for(int i = ;i <= n;i++)
{
cin>>tmp;
money.insert(make_pair(tmp,i));
G[i][i] = ;
}
cin>>m;
string t1,t2;
double t;
for(int i = ;i <= m;i++)
{
cin>>t1>>t>>t2;
G[money[t1]][money[t2]] = t;
}
Floyd();
int flag = ;
for(int i = ;i <= n;i++)
if(G[i][i] > ) {
flag = ;
break;
}
if(flag)
cout<<"Case "<<++countt<<": Yes"<<endl;
else
cout<<"Case "<<++countt<<": No"<<endl;
}
return ;
}

POJ-2240的更多相关文章

  1. 最短路(Floyd_Warshall) POJ 2240 Arbitrage

    题目传送门 /* 最短路:Floyd模板题 只要把+改为*就ok了,热闹后判断d[i][i]是否大于1 文件输入的ONLINE_JUDGE少写了个_,WA了N遍:) */ #include <c ...

  2. poj 2240 Arbitrage (Floyd)

    链接:poj 2240 题意:首先给出N中货币,然后给出了这N种货币之间的兑换的兑换率. 如 USDollar 0.5 BritishPound 表示 :1 USDollar兑换成0.5 Britis ...

  3. POJ 2240 Arbitrage / ZOJ 1092 Arbitrage / HDU 1217 Arbitrage / SPOJ Arbitrage(图论,环)

    POJ 2240 Arbitrage / ZOJ 1092 Arbitrage / HDU 1217 Arbitrage / SPOJ Arbitrage(图论,环) Description Arbi ...

  4. poj 2240 Arbitrage 题解

    Arbitrage Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 21300   Accepted: 9079 Descri ...

  5. poj 2240(floyd)

    http://poj.org/problem?id=2240 题意:有些人会利用货币的不用汇率来进行套现,比如1美元换0.5英镑,而1英镑又可以换10法郎,而1法郎又可以换0.21的美元,那么经过货币 ...

  6. POJ 2240 && ZOJ 1082 Arbitrage 最短路,c++ stl pass g++ tle 难度:0

    http://poj.org/problem?id=2240 用log化乘法为加法找正圈 c++ 110ms,g++tle #include <string> #include <m ...

  7. POJ 2240 Arbitrage(floyd)

    http://poj.org/problem?id=2240 题意 : 好吧,又是一个换钱的题:套利是利用货币汇率的差异进行的货币转换,例如用1美元购买0.5英镑,1英镑可以购买10法郎,一法郎可以购 ...

  8. poj 2240 Arbitrage (最短路 bellman_ford)

    题目:http://poj.org/problem?id=2240 题意:给定n个货币名称,给m个货币之间的汇率,求会不会增加 和1860差不多,求有没有正环 刚开始没对,不知道为什么用 double ...

  9. POJ 2240 Arbitrage【Bellman_ford坑】

    链接: http://poj.org/problem?id=2240 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...

  10. POJ 2240 Arbitrage(判正环)

    http://poj.org/problem?id=2240 题意:货币兑换,判断最否是否能获利. 思路:又是货币兑换题,Belloman-ford和floyd算法都可以的. #include< ...

随机推荐

  1. Android NumberPicker默认外观的修改

    NumberPicker是Android3.0之后引入的一个控件,在以后的TimePicker和DatePicker时间控件里边都有引用,NumberPicker本身并没有提供接口给开发者修改其默认外 ...

  2. 关于apache下同IP多域名支持HTTPS和80跳转HTTPS的配置

    httpd-ssl的配置: Listen 443 NameVirtualHost *:443 AddType application/x-x509-ca-cert .crt AddType appli ...

  3. maven第四章背景案例

    4.3简要设计 4.3.1接口设计 4.3.2模块结构 思想 先定义出核心接口,一个接口可以认为是一个功能,根据接口划分功能 设计模式就是一种思想,外观模式和代理模式,适配者模式三者的区别 http: ...

  4. location.href的用法

    *.location.href 用法: top.location.href=”url”          在顶层页面打开url(跳出框架) self.location.href=”url”       ...

  5. FineUI页面级别的参数配置

    Theme: 控件主题,目前支持三种主题风格(blue/gray/access,默认值:blue) Language: 控件语言(en/zh_CN/zh_TW/...,默认值:zh_CN) FormM ...

  6. linux下查看所有用户及所有用户组

    groups 查看当前登录用户的组内成员groups gliethttp 查看gliethttp用户所在的组,以及组内成员whoami 查看当前登录用户名 /etc/group文件包含所有组/etc/ ...

  7. [java] Java NIO 学习笔记 I

    如今在运行时优化方面,JVM 已然前进了一大步.现在 JVM 运行字节码的速率已经接近本地 编译代码,借助动态运行时优化,其表现甚至还有所超越.这就意味着,多数 Java 应用程序已不 再受 CPU ...

  8. Java语言实现简单FTP软件------>FTP软件远程窗口的实现(六)

    1.首先看一下远程窗口的布局效果 2.看一下本地窗口实现的代码框架 3.远程窗口主要实现代码FtpPanel.java package com.oyp.ftp.panel.ftp; import ja ...

  9. jsp连接MySQL操作GIS地图数据,实现添加point的功能

    index_map.jsp中的代码: <%@ page language="java" pageEncoding="utf-8"%> <%@ ...

  10. MapReduce UnitTest

    通常情况下,我们需要用小数据集来单元测试我们写好的map函数和reduce函数.而一般我们可以使用Mockito框架来模拟OutputCollector对象(Hadoop版本号小于0.20.0)和Co ...