题意:

有n个工厂和m个商店,商店已经存在,而工厂需要建造且需要一定的花费和一定的时间,工厂的建造可以同时建,如果建造了指定的工厂,相应的商店会获得一定的收入。给定一个L,求最少需要花费多长时间去建造一些工厂使得商店获得的收入减去工厂的花费>=L,以及在这个最小时间下的最大利润,不能实现的话输出impossible。

思路:

如果没有时间要求和L去求获得的最大利润,就是一个最大权闭合图的裸体,而现在需要求一个最小时间,其实我们二分一下时间就可以了。

代码:

#include <algorithm>
#include <iostream>
#include <string.h>
#include <cstdio>
#include <queue>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 405;
const int maxm = maxn*maxn;
const int BAS = 200;
struct node
{  int v, w, next;
} edge[maxm];
int no, head[maxn];
int t, n, m, L, UP, all, S, T;
int pay[maxn], ti[maxn];
int pro[maxn];
int bad[maxn];
vector<int> hav[maxn];
queue<int> q;
int rec[maxn], pre[maxn], block[maxn], dis[maxn];
inline void init()
{  no = 0;  memset(head, -1, sizeof head);
}
inline void add(int u, int v, int w)
{  edge[no].v = v; edge[no].w = w;  edge[no].next = head[u]; head[u] = no++;  edge[no].v = u, edge[no].w = 0;  edge[no].next = head[v]; head[v] = no++;
}
void reset(int S, int T)
{   memset(dis, 0x3f, sizeof dis);  memset(block, 0, sizeof block);  q.push(S); dis[S] = 0;  while(!q.empty())  {  int top = q.front(); q.pop();  for(int k = head[top]; k != -1; k = edge[k].next)  if(dis[edge[k].v] == inf && edge[k].w)  dis[edge[k].v] = dis[top]+1, q.push(edge[k].v);  }
}
int dinic(int S, int T)
{  int ans = 0, flow = inf, top = S;  pre[S] = S;  reset(S, T);  while(dis[T] != inf)  {  int k, tmp;  for(k = head[top]; k != -1; k = edge[k].next)  {  if(edge[k].w && dis[edge[k].v]==dis[top]+1 &&   !block[edge[k].v]) break;  }  if(k != -1)  {  tmp = edge[k].v;  flow = min(flow, edge[k].w);  pre[tmp] = top, rec[tmp] = k;  top = tmp;  if(top == T)  {  ans += flow;  for(; top != S; top = pre[top])  {  edge[rec[top]].w -= flow;  edge[rec[top]^1].w += flow;  if(!edge[rec[top]].w) tmp = top;  }  top = pre[tmp], flow = inf;  for(; top != S; top = pre[top])  flow = min(flow, edge[rec[top]].w);  top = pre[tmp];  }  }  else  {  block[top] = 1;  top = pre[top];  if(block[S]) reset(S, T);  }  }  return ans;
}
bool mapping()
{scanf("%d %d %d", &n, &m, &L);UP = 0;for(int i = 1; i <= n; ++i){scanf("%d %d", &pay[i], &ti[i]);  UP = max(UP, ti[i]);add(BAS+i, T, pay[i]);}   for(int i = 1; i <= m; ++i)  {  int k, x;scanf("%d %d", &pro[i], &k);for(int j = 1; j <= k; ++j){scanf("%d", &x);hav[x].push_back(i);add(i, BAS+x, inf);}add(S, i, pro[i]);all += pro[i];}  return all-dinic(S, T) >= L;
}
int work(int p)
{init(); all = 0;memset(bad, 0, sizeof bad);for(int i = 1; i <= n; ++i){if(ti[i] > p){for(int j = 0; j < hav[i].size(); ++j)bad[hav[i][j]] = 1;}else{add(BAS+i, T, pay[i]);for(int j = 0; j < hav[i].size(); ++j)add(hav[i][j], BAS+i, inf); }}for(int i = 1; i <= m; ++i){if(bad[i]) continue;all += pro[i];add(S, i, pro[i]);}return all-dinic(S, T);
}
int main()
{  scanf("%d", &t);for(int _ = 1; _ <= t; ++_){S = BAS*2+1, T = BAS*2+2;for(int i = 0; i <= BAS; ++i) hav[i].clear();all = 0; init(); if(!mapping()) printf("Case #%d: impossible\n", _); else{int mid, l = 0, r = UP;while(l <= r){mid = (l+r)/2;if(work(mid) >= L) r = mid-1;else l = mid+1;}printf("Case #%d: %d %d\n", _, l, work(l));}   }return 0;
}

继续加油~

HDU-5855 Less Time, More profit(最大权闭合图+二分)相关推荐

  1. hdu 3879(最小割模型求解最大权闭合图)

    题意: 公司得到了一共N个可以作为通讯信号中转站的地址,而由于这些地址的地理位置差异,在不同的地方建造通讯中转站需要投入的成本也是不一样的,所幸在前期调查之后这些都是已知数据:建立第i个通讯中转站需要 ...

  2. hdu 3879 Base Station 最大权闭合图

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3879 A famous mobile communication company is plannin ...

  3. HDU 3061 Battle(最小割----最大权闭合图)

    题意: Problem Description 由于小白同学近期习武十分刻苦,很快被晋升为天策军的统帅.而他上任的第一天,就面对了一场极其困难的战斗: 据侦查兵回报,前方共有N座城池,考虑到地势原因, ...

  4. 【POJ - 2987】Firing(最大权闭合图,网络流最小割,输出方案最小,放大权值法tricks)

    题干: You've finally got mad at "the world's most stupid" employees of yours and decided to ...

  5. 【POJ - 2987 】Firing 【最大权闭合图有唯一的 势 】

    You've finally got mad at "the world's most stupid" employees of yours and decided to do s ...

  6. POJ2987-Firing(最大权闭合图)

    Firing Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 10904   Accepted: 3290 Descript ...

  7. luogu P3410 拍照(最大权闭合图转最小割)

    luogu P3410 拍照 最大权闭合图转最小割 要得到最大收益,我们可以用总可能收益减去最小花费,也就是最小割. #include<cstdio> #include<cstrin ...

  8. 【网络流24题】B、太空飞行计划问题(最大权闭合图转最小割、最小割方案输出)

    整理的算法模板合集: ACM模板 B.太空飞行计划问题(最大权闭合图转最小割.最小割方案输出)[省选/NOI- ] P2762 太空飞行计划问题 [问题分析] 最大权闭合图问题,可以转化成最小割问题, ...

  9. 【bzoj1565】[NOI2009]植物大战僵尸 拓扑排序+最大权闭合图

    原文地址:http://www.cnblogs.com/GXZlegend/p/6808268.html 题目描述 输入 输出 仅包含一个整数,表示可以获得的最大能源收入.注意,你也可以选择不进行任何 ...

  10. POJ 2987 Firing(最大权闭合图)

    [题目链接] http://poj.org/problem?id=2987 [题目大意] 为了使得公司效率最高,因此需要进行裁员, 裁去不同的人员有不同的效率提升效果,当然也有可能是负的效果, 如果裁 ...

最新文章

  1. qt-designer使用教程1--HelloWorld
  2. 【转帖】计算机世界:后DRM时代的数字音乐博弈
  3. 在Debian 上安装php zip扩展
  4. Method not found: '!!0[] System.Array.Empty()'.
  5. python哪些模块用于数据分析_python数据解析模块之glom模块的使用(一)
  6. 教学思路C#之入门一 认识简单的C#结构
  7. C++string容器-字符串拼接
  8. CF1271D Portals
  9. 解决js弹窗网页出现白屏
  10. 自编码器图像去噪matlab,深度有趣 | 05 自编码器图像去噪
  11. mongodb创建集合与php扩展
  12. 用正则表达式抓取网络连接的简单实现
  13. Mac 下更新 .bash_profile 文件
  14. python可迭代对象 迭代器生成器_第八章 Python可迭代对象、迭代器和生成器-阿里云开发者社区...
  15. 创建数据透视表数据包含合并单元格
  16. 第二章---《实时语音处理实践指南》发音机理与器件学习笔记
  17. 公众号滑动图代码_公众号怎么制作图片滑动的效果?怎么做可以上下滑动的长图?...
  18. word 添加页眉页脚,添加不同页码
  19. frp与nginx结合,实现内网设备的ssh,远程桌面和http访问
  20. Echarts基本使用(vue实现3D地图)

热门文章

  1. R语言作图——Lollipop chart(棒棒糖图)
  2. Oracle创建表空间,用户,及权限
  3. 【怎么用u盘装系统】
  4. 杭州用城市大脑治堵4年,怎么限牌还玩升级?
  5. 印象最深刻的三位老师、难忘的往事
  6. centos Unison+Inotify双向同步
  7. 恶意代码分析实战——高级反汇编
  8. 河北农大计算机专业全国排名,2019河北农业大学现代科技学院专业排名
  9. R语言length()和lengths()的区别
  10. Eclipse项目中显示隐藏的文件