ACM-ICPC North America Qualifier Units

Source: Internet
Author: User

Test instructions: As its name, give you n units, and n-1 unit conversion information, let you put the complete unit conversion chain written out.

The idea of solving problems: searching or Floyd

Problem Solving Code:

1 //File name:j.cpp2 //Author:darkdream3 //Created time:2015 March 14 Saturday 15:56 31 seconds4 5#include <vector>6#include <list>7#include <map>8#include <Set>9#include <deque>Ten#include <stack> One#include <bitset> A#include <algorithm> -#include <functional> -#include <numeric> the#include <utility> -#include <sstream> -#include <iostream> -#include <iomanip> +#include <cstdio> -#include <cmath> +#include <cstdlib> A#include <cstring> at#include <ctime> - #defineLL Long Long -  - using namespacestd; - Charstr[ -][ +]; - intmp[ A][ A]; in Chartmp1[ +]; - Chartmp2[ +]; to inttmp; + CharC; - intN; the structnode{ *     intsi,v; $}ans[1100];Panax Notoginseng intCMP (Node A, Node B) - { the     returnA.V <B.V; + } A intMain () { the      while(SCANF ("%d", &n)! =EOF) +     { -         if(n = =0) $              Break; $Memset (MP,0,sizeof(MP)); -          for(inti =1; I <= N;i + +) -         { thescanf"%s", Str[i]);  -         }Wuyi         intMX =0 ; the         intMxnum =0;  -          for(inti =1; I <= N-1; i + +) Wu         { -scanf"%s%c%d%s",tmp1,&c,&TMP,TMP2);  About             intta; $             intTB; -              for(intj =1; J <= n;j++) -             { -                 if(strcmp (STR[J],TMP1) = =0 ) A                 { +TA =J; the                      Break; -                 } $             } the              for(intj=1; J <= N;j + +) the             { the                 if(strcmp (STR[J],TMP2) = =0 ) the                 { -TB =J; in                      Break; the                 } the             } AboutMP[TA][TB] =tmp; the         } the         inttt =1; the          while(tt--) +         { -              for(intK =1; K <= N; k + +) the             {Bayi                  for(inti =1; I <= n; i + +) the                      for(intj=1; J <= N; j + +) the                     { -                         if(Mp[i][k]! =0&& Mp[k][j]! =0 )  -                         { theMP[I][J] = mp[i][k] *Mp[k][j]; the                         } the                         if(Mp[i][k]! =0&& Mp[j][k]! =0 ) the                         { -                             if(Mp[i][k] >Mp[j][k]) the                             { theMP[I][J] = mp[i][k]/Mp[j][k]; the}Else{94Mp[j][i] = mp[j][k]/Mp[i][k]; the                             } the                         } the                         if(Mp[k][i]! =0&& Mp[k][j]! =0 )98                         { About                            if(Mp[k][i] >Mp[k][j]) -Mp[j][i] = mp[k][i]/Mp[k][j];101                            Else       102MP[I][J] = mp[k][j]/Mp[k][i];103                         }104                         if(Mp[i][j] >mx) the                         {106MX =Mp[i][j];107Mxnum =i;108                         }109                     } the             }111         } the          for(inti =1; I <=n;i + +)113         { theAns[i].si =i; theANS[I].V =Mp[mxnum][i]; the         }117Sort (ans+1, ans+1+n,cmp);118printf"1%s", Str[mxnum]);119          for(inti =2; I <= N;i + +) -printf"=%d%s", ans[i].v,str[ans[i].si]);121printf"\ n");122     }123 124     return 0; the}
View Code

ACM-ICPC North America Qualifier Units

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.