poj 3614(最大流)
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 6682 | Accepted: 2350 |
Description
To avoid unsightly burns while tanning, each of the C (1 ≤ C ≤ 2500) cows must cover her hide with sunscreen when they're at the beach. Cow i has a minimum and maximum SPF rating (1 ≤ minSPFi ≤ 1,000; minSPFi≤ maxSPFi ≤ 1,000) that will work. If the SPF rating is too low, the cow suffers sunburn; if the SPF rating is too high, the cow doesn't tan at all........
The cows have a picnic basket with L (1 ≤ L ≤ 2500) bottles of sunscreen lotion, each bottle i with an SPF rating SPFi (1 ≤ SPFi ≤ 1,000). Lotion bottle i can cover coveri cows with lotion. A cow may lotion from only one bottle.
What is the maximum number of cows that can protect themselves while tanning given the available lotions?
Input
* Line 1: Two space-separated integers: C and L
* Lines 2..C+1: Line i describes cow i's lotion requires with two integers: minSPFi and maxSPFi
* Lines C+2..C+L+1: Line i+C+1 describes a sunscreen lotion bottle i with space-separated integers: SPFi and coveri
Output
A single line with an integer that is the maximum number of cows that can be protected while tanning
Sample Input
3 2 3 10 2 5 1 5 6 2 4 1
Sample Output
2
题意:N头牛,第I头需要一个SPF的范围是MinSPF~MaxSPF,m个bottle,每个bottle能给C头牛提供定值为P的SPF,求最多有多少头牛可以得到合适的SPF.
解题思路:最大流,m个bottle与源点相连,容量为c,表示每个bottle能够提供给c头牛,n头牛与汇点连容量为1的边,限制了每头牛只能够一个bottle,每个bottle的SPF只要在牛的SPF范围内,就连一条容量为1的边,表示能提供1头牛使用。
这个题目有点卡模板:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;const int maxn = 5005;
const int inf = 0x3f3f3f3f;
struct Edge
{int to,next,flow;
}edge[maxn*maxn];
struct Node
{int minSPF,maxSPF;
}cow[maxn];
int n,m,cnt,pre[maxn],layer[maxn];void addedge(int u,int v,int flow)
{edge[cnt].to = v;edge[cnt].flow = flow;edge[cnt].next = pre[u];pre[u] = cnt++;swap(u,v);edge[cnt].to = v;edge[cnt].flow = 0;edge[cnt].next = pre[u];pre[u] = cnt++;
}bool bfs(int s,int t)
{queue<int> q;memset(layer,-1,sizeof(layer));layer[s] = 0;q.push(s);while(!q.empty()){int u = q.front();q.pop();if(u == t) return true;for(int i = pre[u]; i != -1; i = edge[i].next){int v = edge[i].to;if(layer[v] == -1 && edge[i].flow > 0){layer[v] = layer[u] + 1;q.push(v);}}}return false;
}int dfs(int u,int t,int maxflow)
{if(u == t || maxflow == 0) return maxflow;int uflow = 0;for(int i = pre[u]; i != -1; i = edge[i].next){int v = edge[i].to;if(layer[v] == layer[u] + 1 && edge[i].flow > 0){int flow = min(maxflow - uflow,edge[i].flow);flow = dfs(v,t,flow);if(flow > 0){edge[i].flow -= flow;edge[i^1].flow += flow;uflow += flow;if(uflow == flow) break;}else layer[v] = -1;}}if(uflow == 0) layer[u] = -1;return uflow;
}int dinic(int s,int t)
{int maxflow = 0;while(bfs(s,t) == true)maxflow += dfs(s,t,inf);return maxflow;
}int main()
{int s,t,w,c;while(scanf("%d%d",&n,&m)!=EOF){s = 0, t = n + m + 1;cnt = 0;memset(pre,-1,sizeof(pre));for(int i = 1; i <= n; i++){scanf("%d%d",&cow[i].minSPF,&cow[i].maxSPF);addedge(m+i,t,1);}for(int i = 1; i <= m; i++){scanf("%d%d",&w,&c);addedge(s,i,c);for(int j = 1; j <= n; j++)if(cow[j].minSPF <= w && w <= cow[j].maxSPF)addedge(i,m+j,1);}printf("%d\n",dinic(s,t));}return 0;
}
poj 3614(最大流)相关推荐
- 【贪心】Sunscreen(poj 3614/luogu 2887)
Sunscreen poj 3614 luogu 2887 题目大意: 有n个人,每个人要求选一个价值在minniminn_iminni到maxximaxx_imaxxi的物品,现在有m件物品,每 ...
- POJ - 3614 Sunscreen(贪心/二分图最大匹配-多重匹配/网络流-最大流)
题目链接:点击查看 题目大意:给出n头奶牛,奶牛们现在要晒太阳,每头奶牛需要[l,r]区间内的光照强度,现在有m种防晒霜,每种防晒霜可以让奶牛接受到val数值的光照强度,然后每种防晒霜只有num个,现 ...
- 【POJ 3614 Sunscreen】贪心 优先级队列
题目链接:http://poj.org/problem?id=3614 题意:C头牛去晒太阳,每头牛有自己所限定的spf安全范围[min, max]:有L瓶防晒液,每瓶有自己的spf值和容量(能供几头 ...
- poj 1273 最大流
题目链接:http://poj.org/problem?id=1273 a.EK算法:(Edmond-Karp): 用BFS不断找增广路径,当找不到增广路径时当前流量即为最大流. b.dinic算法: ...
- POJ 3532 基尔霍夫电流定律 + 高斯消元
题意 传送门 POJ 3532 题解 基尔霍夫电流定律(KCLKCLKCL):在集总参数电路中,任一瞬间,流入或流出电路中任一节点的电流代数和恒等于零.若规定流出为正,则流入为负,KCLKCLKCL ...
- POJ 1149 最大流建图 PIGS
题意: 给出猪圈个数 m 和买家人数 n 然后给出m个猪圈的猪的头数.. 接下来 n 行.. 给出mm a1 a2 .. a(mm) k 例如 2 1 5 3 表示第i+1个用户 有mm(2) 个猪圈 ...
- [poj 3436]最大流+输出结果每条边流量
题目链接:http://poj.org/problem?id=3436 大力套kuangbin板过了orz #include<cstdio> #include<cstring> ...
- POJ 1459--最大流算法
cin竟然比scanf慢了十几倍,想不通 #include <iostream> #include <string> #include <vector> #incl ...
- poj 3614 Sunscreen(优先队列+贪心)
Description To avoid unsightly burns while tanning, each of the C (1 ≤ C ≤ 2500) cows must cover her ...
最新文章
- 【upc 9541 矩阵乘法】非正解
- ​GB28181心跳机制探讨和技术实现
- 码农30多岁,要被辞退的时候 怎么办?
- JavaScript 常用方法封装使用
- TCP/IP详解学习笔记(11)-TCP交互数据流,成块数据流
- 经济学家建议茅台国外售价为国内2倍:未来最有可能走向世界的奢侈品牌
- 依赖反转原理,IoC容器和依赖注入:第3部分
- Hadoop-熟悉常用的HDFS操作
- Vivo手机originOS安装谷歌套件服务框架GMS安装谷歌三件套,进Google Play商店下载应用
- 企业微信支付提示请在微信客户端打开链接_微信h5支付?
- MTK G-sensor
- 身在国外,除了克服语言障碍,还得背好99乘法表
- sre8 sre10_透过窥视镜:安全性和SRE
- 爬取某视频网站电影,仅参考学习
- Oasis Sapphire黑客松来袭 | 构建隐私DApp,赢取9000美元奖励!
- 浅议抖音短视频平台的利与弊
- C语言初阶:define定义的常量和宏,关于指针的详细讲解,初步认识结构体的使用
- 赛门铁克为 Google 域名颁发证书
- TMS和WMTS大概对比
- 基于单片机的坐姿(提醒)矫正系统设计
热门文章
- java 找不到mysql驱动_java lib目录添加了mysql驱动包,仍然找不到class??
- 直播预告丨揭秘神策数据销售方法论,一起向 Top Sales 迈进!
- 数据驱动车主 App 产品优化,轻松搞定用户体验与转化
- Javascript代码优化的8个知识点
- Linux学习总结(五十四)LVS nat 模式搭建
- CSS height:100%无效
- 蓝色巨人的硬件业务:存储营收或将下滑
- GPU虚拟化时代的到来(vGPU)!CitrixNVIDIA联合研发虚拟化共享GPU技术预览
- Windows7中的系统健康报告
- 科学家公布地球“裸照”