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的改为- ...
随机推荐
- k8s入门之Deployment(五)
Deployment控制器通常用来部署无状态的应用,这样可以在任意的节点上扩容或者删除,而不用考虑数据的问题,它可以管理pod对象. 一.多副本 1.使用命令行方式创建Deployment 在dev名 ...
- 3D 沙盒游戏之人物的点击行走移动
前言 在 3D 游戏中,都会有一个主人公.我们可以通过点击游戏中的其他位置,使游戏主人公向点击处移动. 那当我们想要实现一个"点击地面,人物移动到点击处"的功能,需要什么前置条件, ...
- 新华三Gen10服务器ILO 5 安装中文语言包
ILO 5 安装中文语言包 在官网下载语言包文件,并解压 选择firmware&OS software,点击右侧的update firmware 选择本地文件,浏览到语言包里面的lpk文件,点 ...
- C#自定义配置文件(一)
C#自定义配置文件 .NET程序中,经常使用Config文件来配置应用程序中经常使用的值,比如数据库连接字符串.最近项目遇到一个需要配置好多节点在配置文件中的需求.为了使配置节点整洁易维护,在代码调用 ...
- 公众号走走看看——js
1.数字转换字符串/字符串转换数字 2.短循环 3.性能测试(执行时间) 4.交换值 5.合并数组(IE不兼容) 6.数组去重 7.判断给定参数是否是数字 8.获取最大最小值.取随机数(arr.len ...
- Spring Framework 远程命令执行漏洞(CVE-2022-22965)
Spring Framework 远程命令执行漏洞 (CVE-2022-22965) 近日,Spring 官方 GitHub issue中提到了关于 Spring Core 的远程命令执行漏洞,该漏洞 ...
- java高级用法之:JNA中的Structure
目录 简介 native中的struct Structure 特殊类型的Structure 结构体数组作为参数 结构体数组作为返回值 结构体中的结构体 结构体中的数组 结构体中的可变字段 结构体中的只 ...
- Java 线程常用操作
继Java线程生命周期继续学习Java线程其他常用操作 线程的常用操作 设置线程名字:setName() 获取线程名称:getName() 线程唯一Id:getId() // 自定义线程名称 Stri ...
- CentOS自动同步时间
安装ntpdate yum install ntpdate -y 测试是否正常 ntpdate cn.ntp.org.cn # 正常情况 [root@centos7 www]# ntpdate cn. ...
- Flask框架实现登录注册功能(mysql数据库)
前言: 本例使用Flask框架完成登录和注册操作,包括前端(index.html,regist.html)和后端(app.py)两部分,前端页面不过多介绍,直接进入后端部分: 逻辑思路: 登录部分:运 ...