• 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;
    }
    
  • 相关阅读:
    linux 分区格式查看
    MDL原理理解
    linux oracle配置开机启动
    oracle em手动配置
    java字符编码详解
    linux oracle 配置监听器
    mysql 生成时间序列数据
    R实用小技巧
    python将文件夹下的所有csv文件存入mysql和oracle数据库
    遗传算法求解最优化问题
  • 原文地址:https://www.cnblogs.com/liulangye/p/2784883.html
Copyright © 2020-2023  润新知