NC25025 [USACO 2007 Nov G]Sunscreen
NC25025 [USACO 2007 Nov G]Sunscreen
题目
题目描述
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 ≤ minSPF_i ≤ 1,000; minSPF_i ≤ maxSPF_i ≤ 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 \(SPF_i\) (\(1 ≤ SPFi ≤ 1,000\)). Lotion bottle \(i\) can cover \(cover_i\) 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?
输入描述
- Line \(1\) : Two space-separated integers: \(C\) and \(L\)
- Lines \(2 \cdots C+1\) : Line \(i\) describes cow \(i\)'s lotion requires with two integers: \(minSPF_i\) and \(maxSPF_i\)
- Lines \(C+2 \cdots C+L+1\) : Line \(i+C+1\) describes a sunscreen lotion bottle \(i\) with space-separated integers: \(SPF_i\) and \(cover_i\)
输出描述
A single line with an integer that is the maximum number of cows that can be protected while tanning.
示例1
输入
3 2
3 10
2 5
1 5
6 2
4 1
输出
2
题解
思路
知识点:枚举,贪心。
我们希望使用防晒的牛是最优选择,即在自己有独立机会时不占用别的牛的可用机会。因此,考虑建立一个能够选择机会少的序列能够优先选择的排序。对于一系列由同一同侧端点的区间,选择最靠近另一端点的防晒是最优的,因为这样使得对小区间的机会影响最小化。再者,通过对这个同一端点从小到大排序,对于每一组同一同侧端点如上操作,就能每次使得选择最优。
我们选择对区间右端点从小到大排序,因此要选择最靠左的可行防晒,于是防晒因从小到大排序来选择。对每右端点对应一系列区间,从小到大选择防晒,使得防晒最靠左。
时间复杂度 \(O(cl)\)
空间复杂度 \(O(c+l)\)
代码
#include <bits/stdc++.h>
using namespace std;
pair<int, int> a[2507], b[2507];
int main() {
std::ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int c, l;
cin >> c >> l;
for (int i = 0;i < c;i++) cin >> a[i].first >> a[i].second;
for (int i = 0;i < l;i++) cin >> b[i].first >> b[i].second;
sort(a, a + c, [&](pair<int, int> a, pair<int, int> b) {return a.second < b.second;});
sort(b, b + l);
int cnt = 0;
for (int i = 0;i < c;i++) {
for (int j = 0;j < l;j++) {
if (b[j].second && a[i].first <= b[j].first && b[j].first <= a[i].second) {
b[j].second--;
cnt++;
break;
}
}
}
cout << cnt << '\n';
return 0;
}
NC25025 [USACO 2007 Nov G]Sunscreen的更多相关文章
- 【BZOJ】【1046】/【POJ】【3613】【USACO 2007 Nov】Cow Relays 奶牛接力跑
倍增+Floyd 题解:http://www.cnblogs.com/lmnx/archive/2012/05/03/2481217.html 神题啊= =Floyd真是博大精深…… 题目大意为求S到 ...
- 【POJ3612】【USACO 2007 Nov Gold】 1.Telephone Wire 动态调节
意甲冠军: 一些树高给出.行一种操作:把某棵树增高h,花费为h*h. 操作完毕后连线,两棵树间花费为高度差*定值c. 求两种花费加和最小值. 题解: 跟NOIP2014 D1T3非常像. 暴力动规是O ...
- BZOJ 1641 USACO 2007 Nov. Cow Hurdles 奶牛跨栏
[题解] 弗洛伊德.更新距离的时候把$f[i][j]=min(f[i][j],f[i][k]+f[k][j])$改为$f[i][j]=min(f[i][j],max(f[i][k],f[k][j])) ...
- USACO 2013 Nov Silver Pogo-Cow
最近因为闲的蛋疼(停课了),所以开始做一些 USACO 的银组题.被完虐啊 TAT 貌似 Pogo-Cow 这题是 2013 Nov Silver 唯一一道可说的题目? Pogo-Cow Descri ...
- USACO翻译:USACO 2013 NOV Silver三题
USACO 2013 NOV SILVER 一.题目概览 中文题目名称 未有的奶牛 拥挤的奶牛 弹簧牛 英文题目名称 nocow crowded pogocow 可执行文件名 nocow crowde ...
- 便宜的回文 (USACO 2007)(c++)
2019-08-21便宜的回文(USACO 2007) 内存限制:128 MiB 时间限制:1000 ms 标准输入输出 题目类型:传统 评测方式:文本比较 题目描述 追踪每头奶牛的去向是一件棘手的任 ...
- NC25043 [USACO 2007 Jan S]Protecting the Flowers
NC25043 [USACO 2007 Jan S]Protecting the Flowers 题目 题目描述 Farmer John went to cut some wood and left ...
- [USACO 2011 Nov Gold] Cow Steeplechase【二分图】
传送门:http://www.usaco.org/index.php?page=viewproblem2&cpid=93 很容易发现,这是一个二分图的模型.竖直线是X集,水平线是Y集,若某条竖 ...
- [USACO 2011 Nov Gold] Above the Median【逆序对】
传送门:http://www.usaco.org/index.php?page=viewproblem2&cpid=91 这一题我很快的想出了,把>= x的值改为1,< x的改为- ...
随机推荐
- SMTP协议解读以及如何使用SMTP协议发送电子邮件
电子邮件协议中POP3协议用于接收邮件,SMTP协议用于发送邮件.SMTP的全称为Simple Mail Transfer Protocol,也就是简单邮件传输协议,字如其名. 相较于POP3而言 ...
- 清除安装的Rancher、K8s
#清除主机的所有容器.挂载.镜像(慎用) docker stop $(docker ps -aq) docker system prune -f docker volume rm $(docker v ...
- PostgreSQL 锁 之 关系级锁
1.关于锁的基本信息 PostgreSQL 有各种各样的技术来锁定某些东西(或者至少是这样称呼的).因此,我将首先用最笼统的术语解释为什么需要锁,可用的锁类型以及它们之间的区别.然后我们将弄清楚 Po ...
- 异步请求与中断 ( XHR,Axios,Fetch对比 )
随着AJAX技术的诞生,前端正式进入了局部刷新和前后端分离的新时代,最初的服务请求技术是XHR,随着技术发展和ES6的诞生,jquery ajax,axios,fetch 等技术的产生让前端的异步请求 ...
- Excel文件读写操作1(xls)
一.Python-Excel常用的库:xlrd(read).xlwt(write).xlutils.openpyxl 1.xlrd 读取Excel文件,支持 .xls 和 .xlsx 格式. 2.x ...
- 干货 | 一文彻底读懂nginx中的location指令
一个执着于技术的公众号 Nginx系列导读 给小白的 Nginx 10分钟入门指南 Nginx编译安装及常用命令 完全卸载nginx的详细步骤 Nginx 配置文件详解 一文带你读懂Nginx反向代理 ...
- clientWidth、offsetWidth、scrollWidth……
1.元素视图属性 clientWidth:元素内容可视区宽度(水平方向 width + 左右 padding). clientHeight:元素内容可视高度(垂直方向 height + 上下paddi ...
- 数据库、MySQL下载与安装、基本SQL语句
数据演变史 # 1.单独的文本文件 没有固定的存放位置 没有固定的数据格式 '''程序彼此无法兼容 没有统一的标准''' # 2.软件开发目录规范 按照文件功能的不同规定了相应的位置 '''文件查找变 ...
- 万字长文深度剖析 RocketMQ 设计原理
幸福的烦恼 张大胖最近是又喜又忧,喜的是业务量发展猛增,忧的是由于业务量猛增,一些原来不是问题的问题变成了大问题,比如说新会员注册吧,原来注册成功只要发个短信就行了,但随着业务的发展,现在注册成功也需 ...
- 189. Rotate Array - LeetCode
Question 189. Rotate Array Solution 题目大意:数组中最后一个元素移到第一个,称动k次 思路:用笨方法,再复制一个数组 Java实现: public void rot ...