zoukankan      html  css  js  c++  java
  • POJ 1860: Currency Exchange 【SPFA】

    套汇问题,从源点做SPFA,如果有一个点入队次数大于v次(v表示点的个数)则图中存在负权回路,能够套汇,如果不存在负权回路,则判断下源点到自身的最长路是否大于自身,使用SPFA时松弛操作需要做调整

    #include<iostream>

    #include<cstdio>

    #include<string.h>

    #include <stdlib.h>

    #include <math.h>

    using namespace std;

    const int maxn=2000;

    double dist[maxn]={0},rate[maxn][maxn]={{0}},ope[maxn][maxn]={{0}},v;

    int n,m,s,cnt[maxn]={0};

    bool spfa(int scr)

    {

       int l=0,r=1,que[10000]={0},visit[maxn]={0},temp;

       que[++l]=scr;

       dist[scr]=v;

       cnt[scr]=1;

       while(l<=r)

        {

           temp=que[l++];

           visit[temp]=0;

           for(int i=1;i<=n;i++)

           {

               if (rate[temp][i]>0 &&dist[i]<(dist[temp]-ope[temp][i])*rate[temp][i])

               {

                   dist[i]=(dist[temp]-ope[temp][i])*rate[temp][i];

                    if (visit[i]==0)

                   {

                        visit[i]=1;

                        que[++r]=i;

                        cnt[i]++;

                        if (cnt[i]>=n)returntrue;

                    }

               }

           }

        }

       return dist[s]>v;

    }

    int main()

    {

       int x,y;

       scanf("%d%d%d%lf",&n,&m,&s,&v);

       for(int i=1;i<=m;i++)

        {

           scanf("%d%d",&x,&y);

           scanf("%lf%lf%lf%lf",&rate[x][y],&ope[x][y],&rate[y][x],&ope[y][x]);

        }

       if(spfa(s))printf("YES ");else printf("NO ");

       return 0;

    }

  • 相关阅读:
    containerd
    0/1 nodes are available: 1 node(s) had taint {node-role.kubernetes.io/master: }
    failed to pull image k8s.gcr.io/kube-controller-manage
    journalctl
    How to use Kata Containers and CRI (containerd plugin) with Kubernetes
    kubelet kubeadm kubectl install
    make an overlay with mount
    2018-2-13-不使用数据结构反转栈
    2018-8-10-卷积神经网络全面解析
    论分布式系统内的节点坏盘感知
  • 原文地址:https://www.cnblogs.com/philippica/p/4006946.html
Copyright © 2011-2022 走看看