码迷,mamicode.com
首页 > 其他好文 > 详细

PKU 百练OJ Arbitrage

时间:2019-01-09 21:45:00      阅读:312      评论:0      收藏:0      [点我收藏+]

标签:enc   pre   文章   while   iostream   ret   参考   second   oat   

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

标签:enc   pre   文章   while   iostream   ret   参考   second   oat   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!