POJ3614 [USACO07NOV]防晒霜Sunscreen
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 9333 | Accepted: 3264 |
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
Source
1 #include <iostream> 2 #include <cstdio> 3 #include <cstdlib> 4 #include <string> 5 #include <algorithm> 6 7 const int INF = 0x7fffffff; 8 const int MAXN = 2500 + 10; 9 10 inline void read(int &x) 11 { 12 x = 0;char ch = getchar(),c = ch; 13 while(ch < '0' || ch > '9')c = ch, ch = getchar(); 14 while(ch <= '9' && ch >= '0')x = x * 10 + ch - '0', ch = getchar(); 15 if(c == '-')x = -x; 16 } 17 18 int l[MAXN], r[MAXN], cnt[MAXN], point[MAXN], num[MAXN], cntt[MAXN], C, L, ans; 19 20 bool cmp(int a, int b) 21 { 22 return l[a] > l[b]; 23 } 24 25 bool cmpp(int a, int b) 26 { 27 return point[a] > point[b]; 28 } 29 30 int main() 31 { 32 //freopen("data.txt", "r", stdin); 33 read(C),read(L); 34 for(register int i = 1;i <= C;++ i) read(l[i]), read(r[i]), cnt[i] = i; 35 for(register int i = 1;i <= L;++ i) read(point[i]), read(num[i]), cntt[i] = i; 36 std::sort(cnt + 1, cnt + 1 + C, cmp); 37 std::sort(cntt + 1, cntt + 1 + L, cmpp); 38 for(register int i = 1;i <= C;++ i) 39 { 40 for(register int j = 1;j <= L;++ j) 41 if(num[cntt[j]] > 0 && r[cnt[i]] >= point[cntt[j]] && l[cnt[i]] <= point[cntt[j]]) 42 { 43 --num[cntt[j]], ++ ans; 44 break; 45 } 46 else if(l[cnt[i]] > point[cntt[j]] ) break; 47 } 48 printf("%d", ans); 49 return 0; 50 }
POJ3614
转载于:https://www.cnblogs.com/huibixiaoxing/p/7323675.html
POJ3614 [USACO07NOV]防晒霜Sunscreen相关推荐
- 洛谷 P2887 [USACO07NOV]防晒霜Sunscreen 解题报告
P2887 [USACO07NOV]防晒霜Sunscreen 题目描述 To avoid unsightly burns while tanning, each of the C (1 ≤ C ≤ 2 ...
- P2887 [USACO07NOV]防晒霜Sunscreen
总感觉贪心哪里不对, 写了个网络流水过去了此题. 建图不难, 从源点向每一种防晒霜连一条容量为防晒霜数量的边, 再 \(O(N^2)\) 地从每一种防晒霜向可行的牛连一条容量为1的边, 最后从每头牛向 ...
- LOI 2887 [USACO07NOV]防晒霜Sunscreen
题目描述 有C个奶牛去晒太阳 (1 <=C <= 2500),每个奶牛各自能够忍受的阳光强度有一个最小值和一个最大值,太大就晒伤了,太小奶牛没感觉. 而刚开始的阳光的强度非常大,奶牛都承受 ...
- (贪心)洛谷P2887 [USACO07NOV]防晒霜Sunscreen
一.算法分析 贪心策略是将牛按照minspf的降序排,然后在尽可能满足当前牛的情况下,优先取spf值大的防晒霜. 这样选择的原因是本题的特点(也是一些其它贪心类问题的特点),即如果我放弃了当前的牛,后 ...
- P2887 [USACO07NOV]防晒霜Sunscreen - 贪心
貌似这种区间贪心题多数是排序加堆来做... 使尽量多的奶牛被抹,需要用最贴近他下限的防晒霜去抹,考虑完他的下限是否可行之后,还要考虑那些要使用相同防晒霜的奶牛,应该优先分配给上限最低的 奶牛按下限,防 ...
- luogu P2887 [USACO07NOV]防晒霜Sunscreen
贪心 #include<bits/stdc++.h> using namespace std; const int N=2505,inf=999999999; typedef pair&l ...
- 【贪心】防晒霜Sunscreen
防晒霜Sunscreen 题目 有C个奶牛去晒太阳 (1 <=C <= 2500),每个奶牛各自能够忍受的阳光强度有一个最小值和一个最大值,太大就晒伤了,太小奶牛没感觉. 而刚开始的阳光的 ...
- POJ3614,P2887-Sunscreen(防晒霜)【贪心】
正题 POJ题目链接:http://poj.org/problem?id=3614 luogu评测记录:https://www.luogu.org/recordnew/lists?uid=52918& ...
- 洛谷 2887 USACO2007NOV 防晒霜Sunscreen 题解
题意简述 有CCC个奶牛晒太阳,但是第iii个奶牛有一个要求,就是阳光值必须在[li,ri][l_i,r_i][li,ri]之间,才能享受晒太阳.阳光强度开始都是∞\infin∞.有SSS种防晒霜 ...
最新文章
- 码农技术炒股之路——抓取日线数据、计算均线和除权数据
- yum工具对软件包安装,删除,更新介绍
- Enterprise Library1.0 -- DataAccess Application Block
- 《nodejs+gulp+webpack基础实战篇》课程笔记(四)-- 实战演练
- java finalize方法的使用
- JS之返回指定位置字符的charAt方法
- tar+openssl加密压缩解压缩
- 如何优雅地抄袭代码?天下代码一大抄,这才是正确的姿势
- 信息安全——对称算法与非对称算法
- django学习笔记:AdminSite界面配置
- 设计师学python还是processing_人人都能学会的processing创意编程能实现什么?
- Spice Windows Client 利用 USBDk 实现USB重定向
- UNIX编程艺术学习笔记-1
- 线性查找与二分查找的平均查找次数的比较
- 20 个实例玩转 Java 8 Stream
- 【无标题】学生成绩管理系统
- Spring源码分析总结(二)-Spring AOP 解析aop:aspectj-autoproxy
- 多旋翼油门量与升力关系
- 关于四叶玫瑰花数的问题
- css加透明边框,CSS3实现透明边框的方法分享