POJ 2240 Arbitrage

Source: Internet
Author: User

Topic Links:

http://poj.org/problem?id=2240

Title Description:

To the N currencies, to the exchange rate between M-currencies, ask whether the conversion between the money to gain benefits,

Problem Solving Ideas:

By test instructions know, this problem not only find a path, so the most suitable is to choose Floyd to solve the problem, Judge Map[i][i] there is no value greater than 1

Ps:floyd template title.

1#include <cstdio>2#include <cstring>3#include <cstdlib>4#include <algorithm>5#include <iostream>6 using namespacestd;7 #defineMAXN 358 CharNAME[MAXN][MAXN];//the names of various currencies9 DoubleMAP[MAXN][MAXN];//Map[i][j]i-->j's exchange rateTen intN; One  A voidinit (); - intFind (Charstr[]); - voidFloyd (); the  - intMain () - { -     intM, I, j, k =0; +     Doubles; -     CharSTR1[MAXN], STR2[MAXN]; +  A      while(SCANF ("%d", &N), N) at     { - init (); -          for(i=0; i<n; i++) -scanf ("%s", Name[i]); -scanf ("%d", &m); -          while(M--) in         { -scanf ("%s%lf%s", STR1, &s, str2); to             intA =find (STR1); +             intb =find (STR2); -MAP[A][B] =s; the         } * Floyd (); $m =0;Panax Notoginseng          for(i=0; i<n; i++) -                 if(Map[i][i] >1) them =1; +         if(m) Aprintf ("Case %d:yes\n", ++k); the         Else +printf ("Case %d:no\n", ++k); -     } $     return 0; $ } -  - voidInit ()//initialized to a the { -     intI, J;Wuyi      for(i=0; i<n; i++) the          for(j=0; j<n; J + +) -MAP[I][J] =1; Wu } - intFind (Charstr[]) About { $     inti; -      for(i=0; i<n; i++) -         if(!strcmp (name[i], str)) -             returni; A } + voidFloyd () the { -     intI, J, K; $      for(i=0; i<n; i++) the          for(k=0; k<n; k++) the              for(j=0; j<n; J + +) theMAP[I][J] = max (Map[i][j], map[i][k]*map[k][j]); the}

POJ 2240 Arbitrage

Related Keywords:
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.