1008 最短路

本文介绍了一种通过检测不同货币间的兑换率是否存在盈利机会的方法。利用 Floyd 算法进行两两货币之间的比较,判断是否能通过一系列转换使得初始货币金额增加。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

                                                                                                         Arbitrage
                       Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
                               Total Submission(s) : 7 Accepted Submission(s) : 5
Problem Description
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.

Input
The input file will contain one or more test cases. Om the first line of each test case there is an integer n (1<=n<=30), representing the number of different currencies. The next n lines each contain the name of one currency. Within a name no spaces will appear. The next line contains one integer m, representing the length of the table to follow. The last m lines each contain the name ci of a source currency, a real number rij which represents the exchange rate from ci to cj and a name cj of the destination currency. Exchanges which do not appear in the table are impossible.
Test cases are separated from each other by a blank line. Input is terminated by a value of zero (0) for n.

Output
For each test case, print one line telling whether arbitrage is possible or not in the format "Case case: Yes" respectively "Case case: No".

Sample Input
3 USDollar BritishPound FrenchFranc 3 USDollar 0.5 BritishPound BritishPound 10.0 FrenchFranc FrenchFranc 0.21 USDollar 3 USDollar BritishPound FrenchFranc 6 USDollar 0.5 BritishPound USDollar 4.9 FrenchFranc BritishPound 10.0 FrenchFranc BritishPound 1.99 USDollar FrenchFranc 0.09 BritishPound FrenchFranc 0.19 USDollar 0

Sample Output
Case 1: Yes Case 2: No
 
 
 
 
 
题意:最短路么~ 就是看看一个货币经过兑换之后能不能变成比原来的更多
用floyd进行两两之间的比较
 
重点:map的应用
代码:
#include<iostream>
#include<map>
#include<string>
using namespace std;
const int maxn=10000;
double map1[maxn][maxn];
int n;
void floyd()//只能 用floyd 因为最后是相乘的形式~ 对于1来说已经是算是负值了 
{
	int k,i,j;
	for(k=1;k<=n;k++)
	 for(i=1;i<=n;i++)
	  for(j=1;j<=n;j++)
	   {
   		if(map1[i][j]<map1[i][k]*map1[k][j])
   		  map1[i][j]=map1[i][k]*map1[k][j];   		 
   	   }
}
int main()
{
   	map<string,int> mp; //map映射 省去了一个下标函数 
	char str[1000];
	char str1[1000],str2[1000];
	double huilv;
	int n2;
	int flag;
	int t=0;
     while(cin>>n,n)
     {
     	 mp.clear();
     	 
    	 for(int i=1;i<=n;i++)
    	  for(int j=1;j<=n;j++)
    	  {
  	    	map1[i][j]=1.0;
  	    }
     	 for(int j=1;j<=n;j++) 
   	     {
   	    	cin>>str;
   	    	mp[str]=j;
   	    //	cout<<mp[str]<<endl;
     	 }
     	 cin>>n2;
    	 for(int i=1;i<=n2;i++)
    	 {
    	 	cin>>str1>>huilv>>str2;
    	 
    	 	int a=mp[str1];
    	 	int b=mp[str2];
    		    map1[a][b]=huilv;
	//	cout<<map1[mp[str1]][mp[str2]]<<endl;	  	    	
 	     }
 	    
         
        
        /*
for(int i=1;i<=n;i++)
        {     	 
 	       for(int j=1;j<=n;j++)
 	       {
       	     	cout<<map1[i][j]<<" ";
       	   }
       	     cout<<endl;
 	     }*/
		  flag=0;
    	floyd();
    	for(int i=1;i<=n;i++)
    	{
	    	if(map1[i][i]>1.0)
	    	  {
  	    		  flag=1;
	    	break;
  	    	}
	    }
	    
	    
	   if(flag)
	  cout<<"Case "<<++t<<": Yes"<<endl; 
		else
		   cout<<"Case "<<++t<<": No"<<endl;
     } 
	 
     return 0;
	
}

 
内容概要:该论文研究增程式电动汽车(REEV)的能量管理策略,针对现有优化策略实时性差的问题,提出基于工况识别的自适应等效燃油消耗小策略(A-ECMS)。首先建立整车Simulink模型和基于规则的策略;然后研究动态规划(DP)算法和等效燃油小策略;接着通过聚类分析将道路工况分为四类,并设计工况识别算法;后开发基于工况识别的A-ECMS,通过高德地图预判工况类型并自适应调整SOC分配。仿真显示该策略比规则策略节油8%,比简单SOC规划策略节油2%,并通过硬件在环实验验证了实时可行性。 适合人群:具备一定编程基础,特别是对电动汽车能量管理策略有兴趣的研发人员和技术爱好者。 使用场景及目标:①理解增程式电动汽车能量管理策略的基本原理;②掌握动态规划算法和等效燃油消耗小策略的应用;③学习工况识别算法的设计和实现;④了解基于工况识别的A-ECMS策略的具体实现及其优化效果。 其他说明:此资源不仅提供了详细的MATLAB/Simulink代码实现,还深入分析了各算法的原理和应用场景,适合用于学术研究和工业实践。在学习过程中,建议结合代码调试和实际数据进行实践,以便更好地理解策略的优化效果。此外,论文还探讨了未来的研究方向,如深度学习替代聚类、多目标优化以及V2X集成等,为后续研究提供了思路。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值