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
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <algorithm> const int INF = 0x7fffffff;
const int MAXN = + ; inline void read(int &x)
{
x = ;char ch = getchar(),c = ch;
while(ch < '' || ch > '')c = ch, ch = getchar();
while(ch <= '' && ch >= '')x = x * + ch - '', ch = getchar();
if(c == '-')x = -x;
} int l[MAXN], r[MAXN], cnt[MAXN], point[MAXN], num[MAXN], cntt[MAXN], C, L, ans; bool cmp(int a, int b)
{
return l[a] > l[b];
} bool cmpp(int a, int b)
{
return point[a] > point[b];
} int main()
{
//freopen("data.txt", "r", stdin);
read(C),read(L);
for(register int i = ;i <= C;++ i) read(l[i]), read(r[i]), cnt[i] = i;
for(register int i = ;i <= L;++ i) read(point[i]), read(num[i]), cntt[i] = i;
std::sort(cnt + , cnt + + C, cmp);
std::sort(cntt + , cntt + + L, cmpp);
for(register int i = ;i <= C;++ i)
{
for(register int j = ;j <= L;++ j)
if(num[cntt[j]] > && r[cnt[i]] >= point[cntt[j]] && l[cnt[i]] <= point[cntt[j]])
{
--num[cntt[j]], ++ ans;
break;
}
else if(l[cnt[i]] > point[cntt[j]] ) break;
}
printf("%d", ans);
return ;
}
POJ3614
POJ3614 [USACO07NOV]防晒霜Sunscreen的更多相关文章
- 洛谷 P2887 [USACO07NOV]防晒霜Sunscreen 解题报告
P2887 [USACO07NOV]防晒霜Sunscreen 题目描述 To avoid unsightly burns while tanning, each of the C (1 ≤ C ≤ 2 ...
- 洛谷P2877 [USACO07NOV]防晒霜Sunscreen
题目 此题有多种贪心方法. 首先简化题意: 有几个在数轴上的区间,和几个在数轴上确定的位置的点,问用这些数目的点,最多能满足多少个区间里有点. 注意:此题跟区间选点问题不一样,每个点只能满足一个区间, ...
- 洛谷 - P2887 - 防晒霜Sunscreen - 贪心
https://www.luogu.org/problemnew/show/P2887 感觉可以: 把防晒霜拆点限制流量为瓶数,奶牛拆点限制流量为1,当某个防晒霜与奶牛匹配时连一条边,求最大流.但是这 ...
- ImageNet2017文件下载
ImageNet2017文件下载 文件说明 imagenet_object_localization.tar.gz包含训练集和验证集的图像数据和地面实况,以及测试集的图像数据. 图像注释以PASCAL ...
- ImageNet2017文件介绍及使用
ImageNet2017文件介绍及使用 文件说明 imagenet_object_localization.tar.gz包含训练集和验证集的图像数据和地面实况,以及测试集的图像数据. 图像注释以PAS ...
- POJ3614 Sunscreen 优先队列+贪心
Description To avoid unsightly burns while tanning, each of the C (1 ≤ C ≤ 2500) cows must cover her ...
- poj3614 Sunscreen【贪心】
Sunscreen Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11772 Accepted: 4143 Descri ...
- 题解 洛谷 P2287 [USACO07NOV]Sunscreen G
原题 传送门 有C个奶牛去晒太阳 (1 <=C <= 2500),每个奶牛各自能够忍受的阳光强度有一个最小值和一个最大值(minSPFi and maxSPFi),太大就晒伤了,太小奶牛没 ...
- POJ--3614 Sunscreen(贪心)
题目 3614 Sunscreen 2500*2500直接排序暴力贪心 #include<iostream> #include<cstring> #include<alg ...
随机推荐
- vim 插入行号
:let i=1000000|g/^/s//\=i.' '/|let i=i+1
- jQuery3动画+创建元素
一.jQuery的动画 1.jQuery自带的动画 1>变化的是width height opacity display <!DOCTYPE html> <html lang= ...
- 子类A继承父类B, A a = new A(); 则父类B构造函数、父类B静态代码块、父类B非静态代码块、子类A构造函数、子类A静态代码块、子类A非静态代码块 执行的先后顺序是
按照先后顺序: 1,静态先于非静态代码库执行(静态代码块随着类的加载而加载,初始化只执行一次) 2,父类先于子类 3,非静态代码块优于构造函数执行 所以执行顺序如下: 父类B静态代码块->子类A ...
- 前端存取cookie
1.存cookie document.cookie="user_phone="+loginMake1Value;//存手机号码cookie//'user_phone'为cookie ...
- idea使用及其快捷键(Jetbrains很多是通用的)(转)
Java程序员肯定会使用idea进行开发,因为其非常强大,很好用,而且可以很傻瓜式导入gradle,用来做SSM项目也很简单 学生是可以使用教育邮箱或者上床学生证使用免费的jetbrains全家桶的, ...
- PL/SQl连接数据库ORA-12154错误
先说说我遇到的问题: 1.在sql/plus下可以正确连接到数据库(oracle10g): 2.检查我机器(64)位环境变量的配置,没问题.path环境变量没问题(C:\oraclexe\app\or ...
- Hadoop 单机安装配置
- BigDecimal的四则运算及小数位数格式
一.加法 BigDecimal b1 = new BigDecimal("20");BigDecimal b2 = new BigDecimal("30");B ...
- 【python之路25】正则表达式
一.正则表达式简介 就其本质而言,正则表达式(或RE)是一种小型的.高度专业化的(在python中),它内嵌在python中,并通过RE模块实现.正则表达式编译成一系列字节码,然后由用C编写的匹配引擎 ...
- 用JetBrains PyCharm 2017.2创建运行Django程序
在JetBrains PyCharm 2017.2里选择 文件(F) 新项目 点击 三角形 运行 修改Urls.py """S14Djngo URL Configur ...