zoukankan      html  css  js  c++  java
  • 1162. Currency Exchange 夜

    http://acm.timus.ru/problem.aspx?space=1&num=1162

    被这句话害了 "Let us call some sequence of the exchange operations simple if no exchange point is used more than once in this sequence."

    根本没有意义  直径 spfa 就行

    代码:

    #include<iostream>
    #include<stdio.h>
    #include<string.h>
    #include<math.h>
    #include<algorithm>
    #include<vector>
    #include<set>
    #include<map>
    #include<string>
    #include<queue>
    #include<stack>
    #include <iomanip>
    using namespace std;
    #define LL long long
    const int INF=0x3f3f3f3f;
    const int N=106;
    int head[N],I;
    struct node
    {
        double r,c;
        int j,next;
    }side[N*2];
    double dist[N];
    void add(int i,int j,double r,double c)
    {
        side[I].j=j;
        side[I].c=c;
        side[I].r=r;
        side[I].next=head[i];
        head[i]=I++;
    }
    bool spfa(int s,double k,int n)
    {
        int num[N];
        bool in[N];
        memset(num,0,sizeof(num));
        memset(in,false,sizeof(in));
        queue<int>qt;
        for(int i=1;i<=n;++i)
        dist[i]=0.0;
        dist[s]=k;
        qt.push(s);
        num[s]=1;
        while(!qt.empty())
        {
            int x=qt.front();qt.pop();
            in[x]=false;
            if(x==s&&dist[x]>k)
            return true;
            for(int t=head[x];t!=-1;t=side[t].next)
            {
                int j=side[t].j;
                if(dist[j]<(dist[x]-side[t].c)*side[t].r)
                {
                    dist[j]=(dist[x]-side[t].c)*side[t].r;
                    while(!in[j])
                    {
                        ++num[j];
                        if(num[j]>=n)
                        return true;
                        in[j]=true;
                        qt.push(j);
                    }
                }
            }
        }
        return false;
    }
    int main()
    {
        //freopen("data.in","r",stdin);
        int n,m,s;
        double k;
        while(cin>>n>>m>>s>>k)
        {
            memset(head,-1,sizeof(head));
            I=0;
            while(m--)
            {
                int a,b;
                double rab,cab,rba,cba;
                cin>>a>>b>>rab>>cab>>rba>>cba;
                add(a,b,rab,cab);
                add(b,a,rba,cba);
            }
            if(spfa(s,k,n))
            cout<<"YES"<<endl;
            else
            cout<<"NO"<<endl;
        }
        return 0;
    }
    
  • 相关阅读:
    WPF获取分辨率2
    怎样将UNIX Shell作为Concurrent Program来运行
    转 FRM40654 Record has been updated Requery block to see change
    各模组相关interface
    EBS 表后缀的含义
    Oracle Form開發Form消息提示
    EBS多组织(OU
    EBS 开发基础知识
    FORM:在不同窗口中传递参数
    AR 金额计算
  • 原文地址:https://www.cnblogs.com/liulangye/p/2784883.html
Copyright © 2011-2022 走看看