HDU 5855Less Time, More profit
Less Time, More profit
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 468 Accepted Submission(s): 172
Each shop needs products from some plants to make profit of proi units.
Building ith plant needs investment of payi units and it takes ti days.
Two or more plants can be built simultaneously, so that the time for building multiple plants is maximum of their periods(ti).
You should make a plan to make profit of at least L units in the shortest period.
For each test case, there are three integers N, M, L described above.
And there are N lines and each line contains two integers payi, ti(1<= i <= N).
Last there are M lines and for each line, first integer is proi, and there is an integer k and next k integers are index of plants which can produce material to make profit for the shop.
1 <= T <= 30
1 <= N, M <= 200
1≤L,ti≤1000000000
1≤payi,proi≤30000
If this plan is impossible, you should print “Case #x: impossible”
最大权闭合图。源点与利润x建边,边权为利润值。花费y与汇建边,权值为花费值。 x与y之间的依赖关系 建边,权值为 无穷。期望总利润-最小割(最大流)就是能获得的最大利润。
本题因为有时间限制,所以加个二分。在满足利润>=L的情况下求最小时间。在最小时间下求最大利润。
/* ***********************************************
Author :guanjun
Created Time :2016/8/17 13:55:10
File Name :hdu5855.cpp
************************************************ */
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <iomanip>
#include <list>
#include <deque>
#include <stack>
#define ull unsigned long long
#define ll long long
#define mod 90001
#define INF 0x3f3f3f3f
#define maxn 10010
#define cle(a) memset(a,0,sizeof(a))
const ull inf = 1LL << ;
const double eps=1e-;
using namespace std;
struct Edge{
int from,to,cap,flow;
};
struct node{
int n,m,s,t;//节点数 边数 源点 汇点
vector<Edge>edges;
vector<int>G[maxn];
bool vis[maxn];
int d[maxn];
int cur[maxn];
void init(int n,int s,int t){
this->n=n;
this->s=s;
this->t=t;
for(int i=;i<n;i++)G[i].clear();
edges.clear();
m=;
}
void addEdge(int from,int to,int cap){
edges.push_back({from,to,cap,});
edges.push_back({to,from,,});
m=edges.size();
G[from].push_back(m-);
G[to].push_back(m-);
}
bool BFS(){
memset(vis,,sizeof vis);
queue<int>que;
que.push(s);
d[s]=;
vis[s]=true;
while(!que.empty()){
int x=que.front();que.pop();
for(int i=;i<G[x].size();i++){
Edge&e=edges[G[x][i]];
if(!vis[e.to]&&e.cap>e.flow){
vis[e.to]=true;
d[e.to]=d[x]+;
que.push(e.to);
}
}
}
return vis[t];
}
int DFS(int x,int a){
if(x==t||a==)return a;
int flow=,f;
for(int& i=cur[x];i<G[x].size();i++){
Edge& e=edges[G[x][i]];
if(d[x]+==d[e.to]&&(f=DFS(e.to,min(a,e.cap-e.flow)))>){
e.flow+=f;
edges[G[x][i]^].flow-=f;
flow+=f;
a-=f;
if(a==)break;
}
}
return flow;
}
int Maxflow(int s,int t){
this->s=s;
this->t=t;
int flow=;
while(BFS()){
memset(cur,,sizeof cur);
flow+=DFS(s,INF);
}
return flow;
}
}ac;
struct Node{
int cost,time;
}nod[]; int shop[][];
int mon[];
int TT,n,m,T,S,L; int judge(int n,int m,int lim){
T=n+m+;
S=;
int tot=;
ac.init(m+n+,S,T);
for(int i=;i<=m;i++){
for(int j=;j<=shop[i][];j++)
ac.addEdge(i,m+shop[i][j],INF);
ac.addEdge(S,i,mon[i]);
tot+=mon[i];
}
for(int i=;i<=n;i++){
if(nod[i].time<=lim){
ac.addEdge(i+m,T,nod[i].cost);
}
else ac.addEdge(i+m,T,INF);
}
tot-=ac.Maxflow(S,T);
return tot;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
//freopen("out.txt","w",stdout); cin>>TT;
for(int t=;t<=TT;t++){
scanf("%d%d%d",&n,&m,&L);
for(int i=;i<=n;i++){
scanf("%d%d",&nod[i].cost,&nod[i].time);
}
for(int i=;i<=m;i++){
scanf("%d %d",&mon[i],&shop[i][]);
for(int j=;j<=shop[i][];j++){
scanf("%d",&shop[i][j]);
}
}
int l=,r=;
int ans=;
while(l<r){
int mid=(r+l)/;
ans=judge(n,m,mid);
if(ans>=L){
r=mid;
}
else l=mid+;
}
ans=judge(n,m,l);//注意这里
printf("Case #%d: ",t);
if(ans>=L)
printf("%d %d\n",l,ans);
else
puts("impossible");
}
return ;
}
HDU 5855Less Time, More profit的更多相关文章
- Yaoge’s maximum profit HDU - 5052
Yaoge’s maximum profit Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/ ...
- HDU 5855 Less Time, More profit 最大权闭合子图
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5855 Less Time, More profit Time Limit: 2000/1000 MS ...
- 【HDU 5855】Less Time, More profit(网络流、最小割、最大权闭合子图)
Less Time, More profit Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/O ...
- HDU 5052 Yaoge’s maximum profit 光秃秃的树链拆分 2014 ACM/ICPC Asia Regional Shanghai Online
意甲冠军: 特定n小点的树权. 以下n每一行给出了正确的一点点来表达一个销售点每只鸡价格的格 以下n-1行给出了树的侧 以下Q操作 Q行 u, v, val 从u走v,程中能够买一个鸡腿,然后到后面卖 ...
- HDU 5855 Less Time, More profit
二分t+最大权闭合图. 很显然二分那个t作为limit.每一个limit下,有一些边不能用了,然后要知道这种情况下怎么选点获得的价值最大. 这么想:一个shop想获得收益,就必须选择某一些plant, ...
- Hdu 5052 Yaoge’s maximum profit(树链剖分)
题目大意: 给出一棵树.每一个点有商店.每一个商店都有一个价格,Yaoge每次从x走到y都能够在一个倒卖商品,从中得取利益.当然,买一顶要在卖之前.可是没次走过一条路,这条路上的全部商品都会添加一个v ...
- HDU 1712 分组背包
ACboy needs your help Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- HDU5855 Less Time, More profit(最大权闭合子图)
题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5855 Description The city planners plan to build ...
- HDU 1505 City Game (hdu1506 dp二维加强版)
F - City Game Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submi ...
随机推荐
- 51nod 1013 3的幂的和 - 快速幂&除法取模
题目地址:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1013 Konwledge Point: 快速幂:https:/ ...
- [Luogu] P3846 [TJOI2007]可爱的质数
题目描述 给定一个质数P(2<=P<2312^{31}231),以及一个整数B(2<=B<P),一个整数N(2<=N<P). 现在要求你计算一个最小的L,满足BL≡ ...
- Python使用Flask框架,结合Highchart,自定义图表样式主题
参考链接:https://www.highcharts.com.cn/docs/themes 1.使用官方提供的主题js文件,只需要在 highcharts.js 后引入对应的文件即可,不用修改原有的 ...
- Win2008 Server搭建流媒体服务(在线看电影)
什么是流媒体服务呢. 所谓流媒体是指采用流式传输的方式在Internet播放的媒体格式, 与需要将整个视频文件全部下载之后才能观看的传统方式相比, 流媒体技术是通过将视频文件经过特殊的压缩方式分成一个 ...
- Python Pandas库的学习(三)
今天我们来继续讲解Python中的Pandas库的基本用法 那么我们如何使用pandas对数据进行排序操作呢? food.sort_values("Sodium_(mg)",inp ...
- 11-看图理解数据结构与算法系列(B树的删除)
删除操作 删除操作比较复杂,主要是因为删除的项可能在叶子节点上也可能在非叶子节点上,而且删除后可能导致不符合B树的规定,这里暂且称之为导致B树不平衡,于是要进行一些合并.左旋.右旋等操作,使之符合B树 ...
- Jmeter关联-获取token值
1. token就是令牌,比如你授权(登录)一个程序时,他就是个依据,判断你是否已经授权该软件:也叫关联 2. cookie就是写在客户端的一个txt文件,里面包括你登录信息之类的,这样你下次在登录某 ...
- 总结:常用的Linux系统监控命令(2)
判断I/O瓶颈 mpstat命令 命令:mpstat -P ALL 1 1000 结果显示: 注意一下这里面的%iowait列,CPU等待I/O操作所花费的时间.这个值持续很高通常可能是I/O瓶颈所导 ...
- android studio配置so文件路径
将一个项目从eclipse上移植到android studio时,发现总是加载不成功库文件,so库文件放在了main/src/libs下的目录. 参考网上资料,studio默认的库文件路径是main/ ...
- Linux下汇编语言学习笔记24 ---
这是17年暑假学习Linux汇编语言的笔记记录,参考书目为清华大学出版社 Jeff Duntemann著 梁晓辉译<汇编语言基于Linux环境>的书,喜欢看原版书的同学可以看<Ass ...