PKU 百练OJ Arbitrage
Posted tangmiao
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PKU 百练OJ Arbitrage相关的知识,希望对你有一定的参考价值。
http://bailian.openjudge.cn/practice/2240/
#include <iostream> #include <string> #include <map> using namespace std; std::map<std::string, int> currency; void floyd(float ER[31][31],int n,int cnt) { for (int k=0;k<n;k++) { for (int i=0;i<n;i++) { for (int j=0;j<n;j++) { if (ER[i][j]<ER[i][k]*ER[k][j]) { ER[i][j] = ER[i][k] * ER[k][j]; } } } } for (int i=0;i<n;i++) { if (ER[i][i]>1) { std::cout << "Case " + to_string(cnt) +": Yes" << std::endl; return; } } std::cout << "Case " + to_string(cnt) + ": No" << std::endl; return; } int main() { int n; int cnt = 1; while (cin >> n) { float ER[31][31] = {0.0}; if (n == 0) { return 0; } for (int i = 0; i < n; i++) { std::string tempString; cin >> tempString; currency.emplace(tempString, i); } int m; cin >> m; for (int i = 0; i < m; i++) { std::string tempFirstCurrency, tempSecondCurrency; float er; cin >> tempFirstCurrency >> er >> tempSecondCurrency; ER[currency[tempFirstCurrency]][currency[tempSecondCurrency]] = er; } floyd(ER, n, cnt); cnt++; } return 0; }
可以参考这篇文章和这个题解
https://www.cnblogs.com/wangyuliang/p/9216365.html
https://www.luogu.org/problemnew/solution/SP9340
以上是关于PKU 百练OJ Arbitrage的主要内容,如果未能解决你的问题,请参考以下文章