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的更多相关文章

  1. 【BZOJ】【1046】/【POJ】【3613】【USACO 2007 Nov】Cow Relays 奶牛接力跑

    倍增+Floyd 题解:http://www.cnblogs.com/lmnx/archive/2012/05/03/2481217.html 神题啊= =Floyd真是博大精深…… 题目大意为求S到 ...

  2. 【POJ3612】【USACO 2007 Nov Gold】 1.Telephone Wire 动态调节

    意甲冠军: 一些树高给出.行一种操作:把某棵树增高h,花费为h*h. 操作完毕后连线,两棵树间花费为高度差*定值c. 求两种花费加和最小值. 题解: 跟NOIP2014 D1T3非常像. 暴力动规是O ...

  3. 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])) ...

  4. USACO 2013 Nov Silver Pogo-Cow

    最近因为闲的蛋疼(停课了),所以开始做一些 USACO 的银组题.被完虐啊 TAT 貌似 Pogo-Cow 这题是 2013 Nov Silver 唯一一道可说的题目? Pogo-Cow Descri ...

  5. USACO翻译:USACO 2013 NOV Silver三题

    USACO 2013 NOV SILVER 一.题目概览 中文题目名称 未有的奶牛 拥挤的奶牛 弹簧牛 英文题目名称 nocow crowded pogocow 可执行文件名 nocow crowde ...

  6. 便宜的回文 (USACO 2007)(c++)

    2019-08-21便宜的回文(USACO 2007) 内存限制:128 MiB 时间限制:1000 ms 标准输入输出 题目类型:传统 评测方式:文本比较 题目描述 追踪每头奶牛的去向是一件棘手的任 ...

  7. 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 ...

  8. [USACO 2011 Nov Gold] Cow Steeplechase【二分图】

    传送门:http://www.usaco.org/index.php?page=viewproblem2&cpid=93 很容易发现,这是一个二分图的模型.竖直线是X集,水平线是Y集,若某条竖 ...

  9. [USACO 2011 Nov Gold] Above the Median【逆序对】

    传送门:http://www.usaco.org/index.php?page=viewproblem2&cpid=91 这一题我很快的想出了,把>= x的值改为1,< x的改为- ...

随机推荐

  1. github ations 入门使用

    在使用之前,我们了解一下什么是 Github Actions. 在 GitHub Actions 的仓库中自动化.自定义和执行软件开发工作流程. 您可以发现.创建和共享操作以执行您喜欢的任何作业(包括 ...

  2. k8s入门之namespace(三)

    namespace的作用就是用来隔离资源,将同一集群中的资源划分为相互隔离的组.同一名称空间内的资源名称要唯一,但不同名称空间时没有这个要求.有些k8s资源对象与名称空间没有关系,例如 Storage ...

  3. JavaWeb和WebGIS学习笔记(五)——使用OpenLayers显示地图

    系列链接: Java web与web gis学习笔记(一)--Tomcat环境搭建 Java web与web gis学习笔记(二)--百度地图API调用 JavaWeb和WebGIS学习笔记(三)-- ...

  4. TCP 连接的建立 & 断开

    TCP 连接的建立过程 一开始,客户端和服务端都处于 close 状态. 先是服务端监听某个端口,此时服务端处于 listen 状态. 这个时候客户端就可以发送连接请求报文了. 第一次握手 客户端会主 ...

  5. linux下redis开机自启动

    将/usr/local/app/redis-4.0.8/redis.conf文件中daemonize no改为daemonize yes 在/etc目录下新建redis目录:mkdir /etc/re ...

  6. Linux 实现静态路由实验

    环境: 四台主机: A主机:eth0 NAT模式 R1主机:eth0 NAT模式,eth1 仅主机模式 R2主机:eth0 桥接模式,eth1仅主机模式 B主机:eth0 桥接模式 手动修改IP地址 ...

  7. 打造一款高逼格的Vim神器

    点击上方"开源Linux",选择"设为星标" 回复"学习"获取独家整理的学习资料! 作者:枫上雾棋 链接:https://segmentfa ...

  8. 1.sprng 简介

    容器(可以用来管理所有的组件(类)) 核心关注:IOC和AOP 1.IOC Inversion(反转) Of Control:控制反转 控制:资源的获取方式 1.主动式(要什么资源自己创建) Pers ...

  9. 安卓导航抽屉 Navigation Drawer 实现沉浸通知栏

    在使用 Navigation Drawer Activity 模版的时候,遇到了通知栏无法完全沉浸的问题,尝试搜索一些现有的解决方法,但是或多或少都会存在一些问题,通过反复尝试找到找到了一种比较靠谱的 ...

  10. 【PyHacker】编写WAF指纹探测与Sqlmap相结合

    使用Python编写探测WAF指纹脚本,再结合到Sqlmap中,这样以后再探测网站时,如果识别到此WAF指纹,就会显示出来.本文属于巡安似海PyHacker系列课程   编写探测识别WAF脚本 00x ...