"topic link"Click here~~
" The main idea" to travel to multiple countries, given the rate of exchange rates between countries, if from the beginning of the final return to the starting point, the proceeds are in accordance with, otherwise does not meet
"Problem-solving ideas"
A ring, with Floyd to calculate the shortest distance and the largest conversion rate, map<string, int > Map < string-point >
Code
/*bnuoj 4291 Arbitrage? AUTHOR:HRW a ring, using Floyd to calculate the shortest distance and the largest conversion rate map<string, int > Map < string-point >*/#include <bits/stdc++.h>using namespace Std;const int maxn = 300;double dp[maxn][maxn];map<string,int>mapp;double eps = 1e-8;int main () {int n, M,i,j,k,a,b,t; String s,s1,s2; while (cin>>n,n) {memset (dp,0,sizeof (DP)); for (I=1; i<=n; i++) {cin>>s; mapp[s]=i;//map String to I dp[i][i]=1;//initialization itself distance is 1} cin>>m; Double x, y; for (i=0; i<m; i++) {cin>>s1>>s2; scanf ("%lf:%lf", &x,&y); DP[MAPP[S1]][MAPP[S2]]=Y/X;//S1 to S2 conversion rate} for (k=1; k<=n; k++) {//floyd calculates the minimum conversion rate for the maximum for (i=1; i< ; =n; i++) {for (j=1; j<=n; J + +) {Dp[i][j]=max (dp[i][j],dp[i][k]*dp[k][j]); }}} bool Flag=false; for (I=1; i<=n; i++) { if (dp[i][i]>1.0) {//presence flag=true; Break }} if (flag) puts ("Arbitrage"); Else puts ("OK"); } return 0;}
"Team Race # #" BNU 4291 Arbitrage? (Floyd shortest path map map)