zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    js产生随机数
    Ajax库的编写及使用
    css水平竖直居中方式
    各大网站css初始化代码【转】
    文档对象模型-DOM(二)
    文档对象模型-DOM(一)
    nav标签使用说明
    html5学习整理-0311
    Python OpenCV —— Arithmetic
    关于python3 OpenCV的安装和配置
  • 原文地址:https://www.cnblogs.com/tangmiao/p/10246706.html
Copyright © 2011-2022 走看看