Arbitrage POJ 2240

Source: Internet
Author: User

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

Test instructions: Now you have n kinds of currency, after the currency is exchanged, eventually still need to be converted into the original currency, if one of the currencies increased, output "Yes", otherwise output "No".

At first, tle, because the position of return 1 was misplaced. At first, I did not think, directly to the final judgment ...

#include <iostream>#include<cstdio>#include<cmath>#include<algorithm>#include<cstdlib>#include<cstring>#include<map>#include<queue>using namespacestd;#defineMAXN 150#defineINF 0x3f3f3f3fintHEAD[MAXN], V[MAXN];DoubleDIST[MAXN];intCNT;structnode{intu, V, next; DoubleW;} MAPS[MAXN];voidADD (intUintVDoubleW) {MAPS[CNT].V=v; MAPS[CNT].W=W; Maps[cnt].next=Head[u]; Head[u]= cnt + +;}intSPFA (ints) {memset (V,0,sizeof(v)); Queue<int>Q;    Q.push (s); V[s]=1;  while(Q.size ()) {intp=Q.front ();        Q.pop (); V[P]=0;  for(intI=HEAD[P]; i!=-1; I=Maps[i].next) {            intQ =maps[i].v; Doublet = dist[p]*MAPS[I].W; if(dist[q]<t) {Dist[q]=T; if(!V[q]) {V[q]=1;                Q.push (q); }            }        }        if(Dist[s] >1)        return 1; }    return 0;}intMain () {intN, M, t=1; Charstr[ -];  while(SCANF ("%d", &N), N) {map<string,int>s;        S.clear ();  for(intI=1; i<=n; i++) {scanf ("%s", str); S[STR]=i; } scanf ("%d", &m); Chara[ -], b[ -]; DoubleC; CNT=0; memset (Head,-1,sizeof(head));  for(intI=1; i<=m; i++) {scanf ("%s%lf%s", A, &C, B);        ADD (S[a], s[b], c); }        intAns =0;  for(intI=1; i<=n; i++)        {             for(intj=1; j<=n; J + +) Dist[j]= -INF; Dist[i]=1; Ans+=SPFA (i); if(ANS) Break; }        if(ANS) printf ("Case %d:yes\n", t++); Elseprintf"Case %d:no\n", t++); }    return 0;}
View Code

Arbitrage POJ 2240

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.