kebab HDU2883
题意:现在有n个人要烤肉,有m个烤肉架,然后给出每个人的烤肉开始时间si,结束时间ei,以及要烤肉的串数num,还有拷一串的时间ti,然后问你能不能满足所有人的要求。
为3572的进阶题
每个人为一个任务 每个任务的需求量为 需求的肉串数量 ni * 每个肉串烤的时间 ti
3572 任务点到时间点的边为1 是因为一次只能一台机器做一个任务
而这题的话 可以多台机器一起加工一个任务
本来这题可以用3575完全一样的方法来做 但是时间点 s e 属于1到1000000
肯定不能把时间点划分为点
所以要将时间段划分为点 :
先是超级源点到每一个客人连 ni*ti
再将所有时间点升序 一共j个 所以就有j-1个时间段
如果排序后的时间段被任务的时间段包含 那么连一条inf的线 inf对答案不影响 因为源点到任务点的连线和时间段到汇点的连线会限制好流量
最后 每个时间段对超级汇点连一条 (time[j+1]-time[j]) * m的连线 表示该时间段的最大工作量 3575为1*m
这两题非常经典 值得学习
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int N = ;
# define inf 0x3f3f3f3f
int p[N],s[N],e[N],v,c,m; struct Edge {
int from, to, cap, flow;
}; bool operator < (const Edge& a, const Edge& b) {
return a.from < b.from || (a.from == b.from && a.to < b.to);
} struct Dinic {
int s,t;
vector<Edge> edges; // 边数的两倍
vector<int> G[N]; // 邻接表,G[i][j]表示结点i的第j条边在e数组中的序号
bool vis[N]; // BFS使用
int d[N]; // 从起点到i的距离
int cur[N]; // 当前弧指针 void init(int n) {
for(int i = ; i <=n; i++) G[i].clear();
edges.clear();
} void AddEdge(int from, int to, int cap) {
edges.push_back((Edge){from, to, cap, });
edges.push_back((Edge){to, from, , });
m = edges.size();
G[from].push_back(m-);
G[to].push_back(m-);
} bool BFS() {
memset(vis, , sizeof(vis));
queue<int> q;
q.push(s);
vis[s] = ;
d[s] = ;
while(!q.empty()) {
int x = q.front();
q.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] = ;
d[e.to] = d[x] + ;
q.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;
}
}g; vector<int> time;
struct node
{
int si,num,ei,ti; }a[N];
int main()
{
int n,m;
while(~scanf("%d%d",&n,&m))
{
int cnt=;
int s=,t=*n+,i,j;
for(i=;i<=n;i++)
{
scanf("%d%d%d%d",&a[i].si,&a[i].num,&a[i].ei,&a[i].ti);
time.push_back(a[i].si);
time.push_back(a[i].ei);
int tmp = a[i].num*a[i].ti;
cnt+=tmp;
g.AddEdge(s,i,tmp);
}
sort(time.begin(),time.end());
for(i=;i<=n;i++)
{
for(j=;j<(time.size()-);j++)
{
if(a[i].si<=time[j] && a[i].ei>=time[j+])
g.AddEdge(i,n+j+,inf); }
}
for(i=;i<(time.size()-);i++)
g.AddEdge(n+i+,t,(time[i+]-time[i])*m);
int ans=g.Maxflow(s,t); if(ans==cnt)
printf("Yes\n");
else
printf("No\n"); g.init(t);
time.clear();
}
return ;
}
kebab HDU2883的更多相关文章
- 【最大流】【HDU2883】【kebab】
题意: 有一个烧烤机,每次最多能烤 m 块肉,现在有 n 个人来买烤肉,每个人到达时间为 si,离开时间为 ei,点的烤肉数量为 ci,点的烤肉所需烘烤时间为 di, 每个人要烤的肉可以分成若干份在同 ...
- HDU2883 kebab(最大流判断满流 + 离散化 + 区间化点)
[题意]: 有一个烤箱,烤箱在一个时刻最多考M个肉串,N个顾客,每个顾客有属性s,n,e,t s是来的时间,n是想要的肉串数量,e是最晚离开的时间,t是烤的时间(几分熟). 顾客的烤肉可以分开烤,比如 ...
- 【HDU2883】kebab——最大流
题目链接 把"时间粒子"作为最大流的计算结果 设置超级源点为 0 顾客点范围为 1 - 204 时间点 205 - 610 超级汇点 615 超级源点与所有顾客连线,容量为需求的烤 ...
- hdu 2883 kebab 网络流
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2883 Almost everyone likes kebabs nowadays (Here a ke ...
- HDU 2883 kebab(最大流)
HDU 2883 kebab 题目链接 题意:有一个烧烤机,每次最多能烤 m 块肉.如今有 n 个人来买烤肉,每一个人到达时间为 si.离开时间为 ei,点的烤肉数量为 ci,每一个烤肉所需烘烤时间为 ...
- hdu 2883 kebab(时间区间压缩 && dinic)
kebab Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Subm ...
- HDU 2883 kebab
kebab Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ID: 2883 ...
- F - kebab HDU - 2883 (最大流构图)
Almost everyone likes kebabs nowadays (Here a kebab means pieces of meat grilled on a long thin stic ...
- 图论--网络流--最大流 HDU 2883 kebab(离散化)
Problem Description Almost everyone likes kebabs nowadays (Here a kebab means pieces of meat grilled ...
随机推荐
- mfc视类中错误:IntelliSense: declaration is incompatible with。。。解决方案
基本情况是我自己写了一个类: class CDib {....} 然后在mfc自动生成的“工程名Dlg.cpp”中使用类CDib,我的工程名是MfcPictureProcessing,所以类是clas ...
- Qt error ------ qRegisterMetaType() 跨线程信号与槽的形参携带
Qt提示: QObject::connect: Cannot queue arguments of type 'FrequencySpectrum' (Make sure 'FrequencySpec ...
- django-pure-pagination 分页插件
官网地址:https://github.com/jamespacileo/django-pure-pagination 官网上有详细的安装和使用介绍
- DNA序列编码中Hairpin的定义和计算
DNA序列编码中Hairpin的定义和计算 觉得有用的话,欢迎一起讨论相互学习~Follow Me 参考文献 [1] 张凯. DNA计算核酸编码优化及算法设计[D]. 2008. [2] Shin, ...
- java字符数组char[]和字符串String之间的转换
java字符数组char[]和字符串String之间的转换 觉得有用的话,欢迎一起讨论相互学习~Follow Me 使用String.valueOf()将字符数组转换成字符串 void (){ cha ...
- Spark记录-官网学习配置篇(二)
### Spark SQL Running the SET -v command will show the entire list of the SQL configuration. #scala/ ...
- VMware vSphere克隆虚拟机
参考资料:http://blog.csdn.net/shen_jz2012/article/details/48416771 1. 首先将你所要克隆的虚拟机关掉 2. 选择你的ESXI服务器 ...
- 机器学习算法整理(七)支持向量机以及SMO算法实现
以下均为自己看视频做的笔记,自用,侵删! 还参考了:http://www.ai-start.com/ml2014/ 在监督学习中,许多学习算法的性能都非常类似,因此,重要的不是你该选择使用学习算法A还 ...
- SQL语句(十三)多表查询
多表查询 1. 笛卡尔乘积 简单格式 SELECT * 或字段列表 FROM 数据表列表 实例 --1. 笛卡尔乘积 (五条件的连接--很多条件无意义) Select * from Student, ...
- Your Prediction Gets As Good As Your Data
Your Prediction Gets As Good As Your Data May 5, 2015 by Kazem In the past, we have seen software en ...