"Team Race # #" BNU 4291 Arbitrage? (Floyd shortest path map map)

Source: Internet
Author: User

"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&lt ; =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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.