题意:
      给你N个位置,每个位置都有金矿数量和仓库数量,然后位置和位置之间的距离给了出来,最后问你吧所有的金矿都放到库里面走的路径 最长的最短 是多少?

思路:
     比较简单的一个题,直接二分答案,然后用最大流是否满流来判断二分方向,还有就是建图的时候不用拆点什么的,一开始建图想麻烦了,都快敲完了才反应过来,具体看代码。

#include<stdio.h>
#include<string.h>
#include<queue>

#define N_node 200  + 10
#define N_edge 90000
#define INF 1000000000

using namespace std;

typedef struct
{
   int to ,cost ,next;
}STAR;

typedef struct
{
   int x ,t;
}DEP;

typedef struct
{
   int a ,b ,c;
}EDGE;

EDGE edge[22000];
STAR E[N_edge];
DEP xin ,tou;
int list[N_node] ,list2[N_node] ,tot;
int deep[N_node];
int aaa[220] ,bbb[220];

void add(int a ,int b ,int c)
{
     E[++tot].to = b;
     E[tot].cost = c;
     E[tot].next = list[a];
     list[a] = tot;
    
     E[++tot].to = a;
     E[tot].cost = c;
     E[tot].next = list[b];
     list[b] = tot;
}

bool BFS_Deep(int s ,int t ,int n)
{
   memset(deep ,255 ,sizeof(deep));
   xin.x = s ,xin.t = 0;
   deep[xin.x] = xin.t;
   queue<DEP>q;
   q.push(xin);
   while(!q.empty())
   {
      tou = q.front();
      q.pop();
      for(int k = list[tou.x] ;k ;k = E[k].next)
      {
          xin.x = E[k].to;
          xin.t = tou.t + 1;
          if(deep[xin.x] != -1 || !E[k].cost)
          continue;
          deep[xin.x] = xin.t;
          q.push(xin);
      }
   }
   for(int i = 0 ;i <= n ;i ++)
   list2[i] = list[i];
   return deep[t] != -1;
}

int minn(int x ,int y)
{
   return x < y ? x : y;
}

int DFS_Flow(int s ,int t ,int flow)
{
   if(s == t) return flow;
   int nowflow = 0;
   for(int k = list2[s] ;k ;k = E[k].next)
   {
       list2[s] = k;
       int to = E[k].to;
       if(deep[to] != deep[s] + 1 || !E[k].cost)
       continue;
       int tmp = DFS_Flow(to ,t ,minn(E[k].cost ,flow - nowflow));
       nowflow += tmp;
       E[k].cost -= tmp;
       E[k^1].cost += tmp;
       if(nowflow == flow) break;
   }
   if(!nowflow) deep[s] = 0;
   return nowflow;
}

int DINIC(int s ,int t ,int n)
{
   int Ans = 0;
   while(BFS_Deep(s ,t ,n))
   {
       Ans += DFS_Flow(s ,t ,INF);
   }
   return Ans;
}

bool ok(int n ,int m ,int sum ,int mid)
{
     memset(list ,0 ,sizeof(list)) ,tot = 1;
     for(int i = 1 ;i <= n ;i ++)
     {
        add(0 ,i ,aaa[i]);
        add(i ,n + 1 ,bbb[i]);
     }
     for(int i = 1 ;i <= m ;i ++)
     if(edge[i].c <= mid)
     {
        add(edge[i].a ,edge[i].b ,INF);
     }
     int flow = DINIC(0 ,n + 1 ,n + 1);
     return  flow == sum;
}
    
int main ()
{
    int n ,m ,i ,sum;
    while(~scanf("%d" ,&n) && n)
    {
        for(sum = 0 ,i = 1 ;i <= n ;i ++)
        {
           scanf("%d" ,&aaa[i]);
           sum += aaa[i];
        }
        for(i = 1 ;i <= n ;i ++)
        scanf("%d" ,&bbb[i]);
        scanf("%d" ,&m);
        for(i = 1 ;i <= m ;i ++)
        scanf("%d %d %d" ,&edge[i].a ,&edge[i].b ,&edge[i].c);
        int low ,up ,mid ,Ans = -1;
        low = 0 ,up = 11000;
        while(low <= up)
        {
           mid = (low + up) >> 1;
           if(ok(n ,m ,sum ,mid))
           {
               Ans = mid;
               up = mid - 1;
           }
           else low = mid + 1;
        }
        Ans == -1 ? puts("No Solution"):printf("%d\n" ,Ans);
    }
    return 0;
}
       

POJ 3228 二分最大流相关推荐

  1. POJ 2112 二分+最大流

    题意: 有k个牛奶机跟c头牛.他们之间有路相连,农民想让每个牛能到其中一个牛奶机,又想让走路最远的牛走得最小. 题解: 求最大值最小,不出意外就是二分了 由于要限制总的路径长度,就不能对每条边限制了, ...

  2. POJ 2112 Optimal Milking(二分+最大流)

    POJ 2112 Optimal Milking 题目链接 题意:给定一些机器和奶牛,在给定距离矩阵,(不在对角线上为0的值代表不可达),每一个机器能容纳m个奶牛.问全部奶牛都能挤上奶,那么走的距离最 ...

  3. POJ3228二分最大流

    题意:       有n个点,每个点有两个权值,金子数量还有仓库容量,金子可以存在自己的仓库里或者是别的仓库里,仓库和仓库之间有距离,问所有金子都必须存到库里最大距离的最小是多少? 思路:       ...

  4. hdu4560 不错的建图,二分最大流

    题意: 我是歌手 Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Total Subm ...

  5. POJ - 2018 二分+单调子段和

    依然是学习分析方法的一道题 求一个长度为n的序列中的一个平均值最大且长度不小于L的子段,输出最大平均值 最值问题可二分,从而转变为判定性问题:是否存在长度大于等于L且平均值大于等于mid的字段和 每个 ...

  6. P4068-[SDOI2016]数字配对【二分,费用流】

    正题 题目链接:https://www.luogu.com.cn/problem/P4068 题目大意 nnn种数字,第iii个是aia_iai​,有bib_ibi​个,价值为ci∗cjc_i*c_j ...

  7. POJ.3281 dining 最大流+拆点

    POJ.3281 dining 最大流+拆点 思路清晰为啥一直WA呢 #include <iostream> #include <cstring> #include <v ...

  8. Drying POJ - 3104 二分

    Drying    POJ - 3104  二分      http://poj.org/problem?id=3104 二分查找作用之一:查找结果,逆向求解. 最让HSQ学长头疼的就是洗衣服了.洗完 ...

  9. POJ 3579 二分答案

    POJ 3579 二分答案 文章目录 POJ 3579 二分答案 题目 思路 代码 题目 思路 排序,二分一下答案,然后对于每一个元素看一看加上这个答案tmp之后,在数列里面排在哪里,比a[i]+tm ...

最新文章

  1. 谷歌 chrome 浏览器开发者工具打不开的解决方法
  2. ASP中利用OWC控件实现图表功能详解[zz]
  3. 《Python入门经典》——导读
  4. Linux系统管理(六)
  5. sap.ui.layout.HorizontalLayout is not a constructor
  6. Proxy Pattern using C# (转载)
  7. mysql中使用sqldriverconnect()报错的解决
  8. c语言数组插入一个数字 移位,如何将一个数组的元素循环左移?
  9. Windows Embedded Webcast 2008年1月预告
  10. mybatis缓存查找顺序
  11. 产品读书《用户故事与敏捷方法》
  12. 360与百度的竞争分析
  13. 2021计算机考研408真题和答案(回忆版)
  14. 完美tbody滚动效果
  15. oracle存储过程语法累加,Oracle 存储过程语法总结及练习
  16. Python教程视频千锋最新版免费分享
  17. 泰肯星球(Token Planets)基于EOS区块链技术的虚拟游戏
  18. 计算机网络 组网试验,计算机网络 路由器组网实验报告.doc
  19. 自动生成sitemap地图PHP代码
  20. steam 好友网络无法访问解决方法

热门文章

  1. 也许这就是一种技术成就梦想的理解吧
  2. JSP2.0语法初步掌握(学习笔记)
  3. 关于mybatis中基本类型条件判断问题
  4. 匿名对象和object的转换
  5. 谷歌Analytics添加到您的SharePoint 2010网站的2种方法
  6. easyUI menu动态添加
  7. legend3---lavarel常用artisan命令操作
  8. HDOJ1540 - Tunnel Warfare 线段树区间合并
  9. Luogu 1541 乌龟棋
  10. 【转】Java学习---Java Web基础面试题整理