HDU 1217 Arbitrage (Floyd)
Arbitrage
http://acm.hdu.edu.cn/showproblem.php?pid=1217
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.
Test cases are separated from each other by a blank line. Input is terminated by a value of zero (0) for n.
解题思路:将货币种类的名字转化为数字,用其作为货币相互转换的下标,然后用Floyd算出货币之间转换后的最多货币,再寻找自己转换为自己大于1的情况,如果有就输出Yes, 没有就输出No
解题代码:
// File Name: Arbitrage 1217.cpp
// Author: sheng
// Created Time: 2013年07月19日 星期五 15时57分20秒 #include <math.h>
#include <string.h>
#include <stdio.h>
#include <string>
#include <iostream>
#include <map>
using namespace std; const int max_n = ;
map<string, int> k; double cas[max_n][max_n]; int main()
{
string str1, str2;
int n, m, T = ;
while (scanf("%d", &n) != EOF && n)
{
k.clear();
memset (cas, , sizeof (cas));
for (int i = ; i <= n; i ++)
{
cin >> str1;
k[str1] = i;//转换为数字
}
scanf ("%d", &m);
while (m --)
{
double temp;
cin >> str1;
cin >> temp;
cin >> str2;
cas[k[str1]][k[str2]] = temp;
}
for (int i = ; i <= n; i ++)
for (int j = ; j <= n; j ++)
for (int k = ; k <= n; k ++)
{
if (cas[j][k] < cas[j][i] * cas[i][k])
cas[j][k] = cas[j][i] * cas[i][k];
}
int i;
for (i = ; i <= n; i ++)
if (cas[i][i] > )
{
printf ("Case %d: Yes\n", T++);
break;
}
if (i > n)
printf ("Case %d: No\n", T++);
}
return ;
}
HDU 1217 Arbitrage (Floyd)的更多相关文章
- POJ 2240 Arbitrage / ZOJ 1092 Arbitrage / HDU 1217 Arbitrage / SPOJ Arbitrage(图论,环)
POJ 2240 Arbitrage / ZOJ 1092 Arbitrage / HDU 1217 Arbitrage / SPOJ Arbitrage(图论,环) Description Arbi ...
- hdu 1217 (Floyd变形)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=1217 Arbitrage Time Limit: 2000/1000 MS (Java/Others) ...
- hdu 1217 Arbitrage (最小生成树)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1217 /************************************************* ...
- HDU 1217 Arbitrage(Bellman-Ford判断负环+Floyd)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1217 题目大意:问你是否可以通过转换货币从中获利 如下面这组样例: USDollar 0.5 Brit ...
- HDU 1217 Arbitrage(Floyd的应用)
给出一些国家之间的汇率,看看能否从中发现某些肮脏的......朋友交易. 这是Floyd的应用,dp思想,每次都选取最大值,最后看看自己跟自己的.....交易是否大于一.... #include< ...
- hdu 1217 Arbitrage (spfa算法)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1217 题目大意:通过货币的转换,来判断是否获利,如果获利则输出Yes,否则输出No. 这里介绍一个ST ...
- hdu 1217 Arbitrage(佛洛依德)
Arbitrage Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total S ...
- hdu 1217 Arbitrage
Flody多源最短路 #include<cstdio> #include<cstring> #include<string> #include<cmath&g ...
- hdu 1217 汇率 Floyd
题意:给几个国家,然后给这些国家之间的汇率.判断能否通过这些汇率差进行套利交易. Floyd的算法可以求出任意两点间的最短路径,最后比较本国与本国的汇率差,如果大于1,则可以.否则不可以. 有向图 一 ...
随机推荐
- 【转】Java JDBC连接SQL Server2005错误:通过端口 1433 连接到主机 localhost 的 TCP/IP 连接失败
错误原因如下: Exception in thread "main" org.hibernate.exception.JDBCConnectionException: Cannot ...
- OpenStack:安装Keystone
>安装Keystone1. 安装# apt-get install keystone2. 创建dbcreate database keystone;grant all privileges on ...
- ubuntu14.04字符界面中文乱码及中文输入
作为ubuntu用户字符界面是绝对不陌生的,尤其是维护管理服务器的朋友为了节省资源都是用的字符界面,但是默认字符界面中文目录文件都是乱码,根本无法打开编辑,那么怎么让字符界面显示中文目录文件,还有在字 ...
- iOS开发之Pch预编译文件的创建
在Xcode6之前,创建一个新工程xcode会在Supporting files文件夹下面自动创建一个“工程名-Prefix.pch”文件,也是一个头文件,pch头文件的内容能被项目中的其他所有源文件 ...
- SQL 执行顺序
SQL 是一种声明式语言,与其他语言相比它的最大特点是执行顺序-并非按照语法顺序来执行.因此很多程序猿看到SQL就头疼,我之前也是这样,后来看到一篇文章后豁然开朗-地址. 理解了SQL的执行顺序无疑对 ...
- [转]安装openoffice,并且配置为windows服务
[转]安装openoffice,并且配置为windows服务 http://blog.csdn.net/zzzz3621/article/details/18400277 下载windows reso ...
- mozilla css developer center
https://developer.mozilla.org/en-US/docs/Web/CSS
- WPF——数据绑定(一)什么是数据绑定
注意:本人初学WPF,文中可能有表达或者技术性问题,欢迎指正!谢谢! 一:什么是数据绑定? “Windows Presentation Foundation (WPF) 数据绑定为应用程序提供了一种简 ...
- 四则运算之C++版
一.设计思想 之前的版本是用Java语言实现的,在这次的练习中,我用C++语言将其功能逐一实现,其实C++与Java有很多相似之处,只是一些书写格式不同,思路还是一样的. 二.源代码 #include ...
- 新 四则运算题目 C++
源代码: #include <stdlib.h>#include <iostream.h>#include <conio.h>#include <time.h ...