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的改为- ...
随机推荐
- 2021.12.15 P2328 [SCOI2005]超级格雷码(找规律填空)
2021.12.15 P2328 [SCOI2005]超级格雷码(找规律填空) https://www.luogu.com.cn/problem/P2328 题意: 输出n位B进制的格雷码. 分析: ...
- 2021.08.09 P6037 Ryoku的探索(基环树)
2021.08.09 P6037 Ryoku的探索(基环树) P6037 Ryoku 的探索 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn) 重点: 1.树的性质 2.基环树的性质 ...
- python基础练习题(斐波那契数列)
day4 --------------------------------------------------------------- 实例006:斐波那契数列 题目 斐波那契数列. 题目没说清楚, ...
- .Net中字符串不变性与相等判断的特殊场景
今天写bug的时候帮同事解决了一个有趣的问题,可能很多人都会答错.分享给大家. 问题 请看以下例子,并回答问题. var s1 = "12"; var s2 = "12& ...
- oauth协议原理
oauth协议关系图(如获取微信用户信息): oauth一般授权步骤:
- 《Streaming Systems》第二章: 数据处理中的 What, Where, When, How
本章中,我们将通过对 What,Where,When,How 这 4 个问题的回答,逐步揭开流处理过程的全貌. What:计算什么结果? 也就是我们进行数据处理的目的,答案是转换(transforma ...
- 解决:Could not resolve dependencies for project xxx: Could not find artifact xxx
引言 运行A module,找不到B module的依赖报错.A.B module都在project中. 报错信息 [INFO] Scanning for projects... [INFO] [IN ...
- HMS Core分析服务助您掌握用户分层密码,实现整体收益提升
随着市场愈发成熟,开发者从平衡收益和风险的角度开始逐步探索混合变现的优势,内购+广告就是目前市场上混合变现的主要方式之一. 对于混合变现模式,您是否有这样的困惑: 如何判断哪些用户更愿意看广告.哪些用 ...
- 百度SEO算法技术的局限性,怎么做才能有收益
不知道大家有没有发现,我们使用百度的频率在减少,就算有时遇到一些问题,需要用百度来寻找答案,也会经常遇到搜索不到答案的情况.到底是出了什么问题?难道网络上的资源不够丰富了?浩如烟海的互联网,居然搜索不 ...
- JavaScript 任务池
JavaScript 任务池 本文写于 2022 年 5 月 13 日 线程池 在多线程语言中,我们通常不会随意的在需要启动线程的时候去启动,而是会选择创建一个线程池. 所谓线程池,本意其实就是(不止 ...