[2016-04-13] [POJ] [1860] [Currency Exchange]

Source: Internet
Author: User

    • Time: 2016-04-13-23:48:46
    • Topic number: [2016-04-13][poj][1860][currency Exchange]
    • The main idea: Currency exchange, ask the last can be changed by the way make money more,
    • Analysis:
      • Direct SPFA Determine if there is a ring, and if so, it can add value indefinitely.
      • If there is no positive ring, then directly determine whether the final d[s] is greater than the initial value
  
 
  1. #include<cstdio>
  2. #include<vector>
  3. #include<cstring>
  4. #include<queue>
  5. using namespace std;
  6. const int maxn = 100 + 10;
  7. struct Edge{
  8. int ; double c R
  9. edge ( int _v = 0 double _c = 0 , Span class= "KWD" >double _r = Span class= "lit" >0 ): v ( _v ), c ( _c r ( _r Span class= "pun") {}
  10. };
  11. vector<Edge> e[maxn];
  12. void ini(int n ){
  13. for(int i = 0 ; i <= n ; ++i){
  14. e[i].clear();
  15. }
  16. }
  17. void addedge(int u,int v,double c,double r){
  18. e[u].push_back(Edge(v,c,r));
  19. }
  20. int cnt[maxn];double d[maxn];
  21. bool spfa(int s,int n,double v){
  22. for ( int i = 0 ; I <= n ++ i ) D [ i = 0
  23. d[s] = v;
  24. queue<int> q;q.push(s);
  25. memset(cnt, 0 , sizeof(cnt));
  26. cnt[s] = 1;
  27. while(!q.empty()){
  28. int u = q.front();
  29. q.pop();
  30. for ( int i = 0 ; I < e [ u . size i
  31. int v = e [ u ][ i . v
  32. if ( d [ v < ( d [ u - e [ u ][ i c * e [ u ][ i r
  33. D [v ] = Span class= "PLN" > ( d [ u - e [ u ][ i c * e [ u ][ i r
  34. q.push(v);
  35. if(++cnt[v] > n) return true;
  36. }
  37. }
  38. }
  39. return d[s] > v;
  40. }
  41. int main(){
  42. int n,m,s;
  43. double v;
  44. scanf("%d%d%d%lf",&n,&m,&s,&v);
  45. for ( int i = 0 ; I < m ++ i ) {
  46. int b double rab cab Span class= "pun", rba CBA Span class= "pun";
  47. scanf("%d%d%lf%lf%lf%lf",&a,&b,&Rab,&Cab,&Rba,&Cba);
  48. addedge(a,b,Cab,Rab);
  49. addedge(b,a,Cba,Rba);
  50. }
  51. puts(spfa(s,n,v)?"YES":"NO");
  52. return 0;
  53. }


From for notes (Wiz)

[2016-04-13] [POJ] [1860] [Currency Exchange]

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.