杭电1217
来源:互联网 发布:杭州淘宝代运营收费 编辑:程序博客网 时间:2024/04/29 03:17
题目描述:
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.
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.
弗洛伊德算法,最短路径,AC代码:
using System;namespace a1{class Program{public const int M = 50;public static string[] countries = new string[M];public static double[][] relation = new double[M][];public static int find(string s, int n){ int mid = -1, high = n - 1, low = 0; while (low <= high) { mid = (low + high) / 2; if (countries[mid] == s)return mid;else if (string.Compare(countries[mid], s) < 0)low = mid + 1;elsehigh = mid - 1; } return -1; }public static void Main(string[] args){int n, m, i, p, q, ce = 0;string a, b; double t; string str = string.Empty;while ((str = Console.ReadLine()) != null) {n = Convert.ToInt32(str);if (n == 0)break;ce++; for (i = 0; i < n; i++) {relation[i] = new double[n];for (int j = 0; j < n; j++)relation[i][j] = 0;} for (i = 0; i < n; i++) {str = Console.ReadLine();countries[i] = str;relation[i][i] = 1;} Array.Sort(countries,0,n);str = Console.ReadLine();m = Convert.ToInt32(str);for (i = 1; i <= m; i++) { str = Console.ReadLine();string[] s = str.Split(' ');a = s[0];t = Convert.ToDouble(s[1]);b = s[2];p = find(a, n); q = find(b, n); relation[p][q] = t; } Console.ReadLine();for (i = 0; i < n; i++)for (p = 0; p < n; p++)for (q = 0; q < n; q++)if (relation[p][i] * relation[i][q] > relation[p][q])relation[p][q] = relation[p][i] * relation[i][q]; for (i = 0; i < n; i++)if (relation[i][i] > 1)break; if (i >= n)Console.WriteLine("Case {0}: No", ce);elseConsole.WriteLine("Case {0}: Yes", ce); }}}}
0 0
- 杭电1217&&poj2240Arbitrage
- 杭电1217
- 杭电
- 杭电
- 杭电
- 杭电 1234 和 杭电 2115
- 杭电2056之Rectangles 杭电
- 杭电ACM1061Rightmost Digit
- 杭电2099 7.11
- 杭电ACM 1003
- 杭电 ACM 2016
- 杭电ACM1466
- 杭电ACM1003
- 杭电ACM1225
- 杭电ACM2023
- 杭电ACM2602
- 杭电ACM2955
- 杭电ACM3198
- Linux查看JDK的安装路径和JAVA_HOME的环境变量设置
- ZOJ-3923-In the Rain
- Win7 自带IIS7局域网无法访问解决办法
- CoreLocation.framework框架基本用法
- pat1016:部分A+B
- 杭电1217
- [C语言][LeetCode][83]Remove Duplicates from Sorted List
- 深入理解SetUID
- c++primer(第五版) 第十二章 动态内存习题答案
- Maximal Information Coefficient 最大信息系数
- 在终端上访问网站和下载文件
- pat1017:A除以B
- iOS开发之自定义手势
- 安装oracle客户端,配置plsql