首页 > 其他 > 详细

PKU 百练OJ Arbitrage

时间:2019-01-09 21:06:17      阅读:229      评论:0      收藏:0      [点我收藏+]
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

原文:https://www.cnblogs.com/tangmiao/p/10246706.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!