"HDU" 3696 Farm Game

Source: Internet
Author: User

SPFA to find the shortest path. When you see the picture, pay attention to the inverse building plan.

1 /*3696*/2#include <iostream>3#include <queue>4#include <vector>5#include <algorithm>6#include <cstdio>7#include <cstring>8#include <cmath>9#include <cstdlib>Ten using namespacestd; One  A #defineMAXN 10005 - #defineMAXV 10005 - #defineMaxe 50005 the  -  -typedefstruct { -     intV, next; +     DoubleR; - } edge_t; +  A Const DoubleINF =9999999.; at edge_t E[maxe]; - intL, HEAD[MAXN]; - DoubleW[MAXN], P[MAXN]; - DoubleRATE[MAXN]; - BOOLVISIT[MAXN]; - intN, M; in  - voidAddedge (intUintVDoubler) { toE[L].V =v; +E[l].next =Head[u]; -E[L].R =R; theHead[u] = l++; * } $ Panax Notoginseng voidinit () { -Memset (Head,-1,sizeof(int) * (n+1)); theL =0; + } A  the voidSPFA (intu) { +     intI, J, K, V; -queue<int>Q; $      $      for(i=0; i<=n; ++i) -Rate[i] =-INF; -memset (Visit,false,sizeof(visit)); theRate[u] =0.0; -Visit[u] =true;Wuyi q.push (u); the      -      while(!P.empty ()) { WuU =Q.front (); - Q.pop (); AboutVisit[u] =false; $          for(I=head[u]; i!=-1; I=E[i].next) { -v =e[i].v; -             if(Rate[v] < rate[u]+E[I].R) { -RATE[V] = Rate[u] +E[I].R; A                 if(!Visit[v]) { +VISIT[V] =true; the Q.push (v); -                 } $             } the         } the     } the } the  - intMain () { in     intI, J, K; the     intu, v; the     DoubleR, ans; About      the #ifndef Online_judge theFreopen ("data.in","R", stdin); theFreopen ("Data.out","W", stdout); +     #endif -      the      while(SCANF ("%d", &n)!=eof &&N) {Bayi init (); the          for(i=1; i<=n; ++i) { thescanf"%LF%LF", &p[i], &w[i]); -Addedge (0, I, log (p[i])); -         } thescanf"%d", &m); the          while(m--) { thescanf"%d%d", &k, &u); the--K; -              while(k--) { thescanf"%lf%d", &r, &v); the Addedge (V, U, log (r)); theU =v;94             } the         } theSPFA (0); theAns =0.0;98          for(i=1; i<=n; ++i) { AboutR =exp (rate[i]); -             if(P[i] <R)101P[i] =R;102Ans + = p[i]*W[i];103         }104printf"%.2lf\n", ans); the     }106     107     return 0;108}

"HDU" 3696 Farm Game

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.