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; minSPFimaxSPFi ≤ 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

USACO 2007 November Gold
【题解】
把min从大到小排序,然后对于每个区间,放最大的SPF。分情况讨论两个区间的先后位置可得证,证明显然。
还可用二分图最大匹配做。

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstdlib>
 4 #include <string>
 5 #include <algorithm>
 6
 7 const int INF = 0x7fffffff;
 8 const int MAXN = 2500 + 10;
 9
10 inline void read(int &x)
11 {
12     x = 0;char ch = getchar(),c = ch;
13     while(ch < '0' || ch > '9')c = ch, ch = getchar();
14     while(ch <= '9' && ch >= '0')x = x * 10 + ch - '0', ch = getchar();
15     if(c == '-')x = -x;
16 }
17
18 int l[MAXN], r[MAXN], cnt[MAXN], point[MAXN], num[MAXN], cntt[MAXN], C, L, ans;
19
20 bool cmp(int a, int b)
21 {
22     return l[a] > l[b];
23 }
24
25 bool cmpp(int a, int b)
26 {
27     return point[a] > point[b];
28 }
29
30 int main()
31 {
32     //freopen("data.txt", "r", stdin);
33     read(C),read(L);
34     for(register int i = 1;i <= C;++ i) read(l[i]), read(r[i]), cnt[i] = i;
35     for(register int i = 1;i <= L;++ i) read(point[i]), read(num[i]), cntt[i] = i;
36     std::sort(cnt + 1, cnt + 1 + C, cmp);
37     std::sort(cntt + 1, cntt + 1 + L, cmpp);
38     for(register int i = 1;i <= C;++ i)
39     {
40         for(register int j = 1;j <= L;++ j)
41             if(num[cntt[j]] > 0 && r[cnt[i]] >= point[cntt[j]] && l[cnt[i]] <= point[cntt[j]])
42             {
43                 --num[cntt[j]], ++ ans;
44                 break;
45             }
46             else if(l[cnt[i]] > point[cntt[j]] ) break;
47     }
48     printf("%d", ans);
49     return 0;
50 }

POJ3614

转载于:https://www.cnblogs.com/huibixiaoxing/p/7323675.html

POJ3614 [USACO07NOV]防晒霜Sunscreen相关推荐

  1. 洛谷 P2887 [USACO07NOV]防晒霜Sunscreen 解题报告

    P2887 [USACO07NOV]防晒霜Sunscreen 题目描述 To avoid unsightly burns while tanning, each of the C (1 ≤ C ≤ 2 ...

  2. P2887 [USACO07NOV]防晒霜Sunscreen

    总感觉贪心哪里不对, 写了个网络流水过去了此题. 建图不难, 从源点向每一种防晒霜连一条容量为防晒霜数量的边, 再 \(O(N^2)\) 地从每一种防晒霜向可行的牛连一条容量为1的边, 最后从每头牛向 ...

  3. LOI 2887 [USACO07NOV]防晒霜Sunscreen

    题目描述 有C个奶牛去晒太阳 (1 <=C <= 2500),每个奶牛各自能够忍受的阳光强度有一个最小值和一个最大值,太大就晒伤了,太小奶牛没感觉. 而刚开始的阳光的强度非常大,奶牛都承受 ...

  4. (贪心)洛谷P2887 [USACO07NOV]防晒霜Sunscreen

    一.算法分析 贪心策略是将牛按照minspf的降序排,然后在尽可能满足当前牛的情况下,优先取spf值大的防晒霜. 这样选择的原因是本题的特点(也是一些其它贪心类问题的特点),即如果我放弃了当前的牛,后 ...

  5. P2887 [USACO07NOV]防晒霜Sunscreen - 贪心

    貌似这种区间贪心题多数是排序加堆来做... 使尽量多的奶牛被抹,需要用最贴近他下限的防晒霜去抹,考虑完他的下限是否可行之后,还要考虑那些要使用相同防晒霜的奶牛,应该优先分配给上限最低的 奶牛按下限,防 ...

  6. luogu P2887 [USACO07NOV]防晒霜Sunscreen

    贪心 #include<bits/stdc++.h> using namespace std; const int N=2505,inf=999999999; typedef pair&l ...

  7. 【贪心】防晒霜Sunscreen

    防晒霜Sunscreen 题目 有C个奶牛去晒太阳 (1 <=C <= 2500),每个奶牛各自能够忍受的阳光强度有一个最小值和一个最大值,太大就晒伤了,太小奶牛没感觉. 而刚开始的阳光的 ...

  8. POJ3614,P2887-Sunscreen(防晒霜)【贪心】

    正题 POJ题目链接:http://poj.org/problem?id=3614 luogu评测记录:https://www.luogu.org/recordnew/lists?uid=52918& ...

  9. 洛谷 2887 USACO2007NOV 防晒霜Sunscreen 题解

    题意简述 有CCC个奶牛晒太阳,但是第iii个奶牛有一个要求,就是阳光值必须在[li,ri][l_i,r_i][li​,ri​]之间,才能享受晒太阳.阳光强度开始都是∞\infin∞.有SSS种防晒霜 ...

最新文章

  1. 码农技术炒股之路——抓取日线数据、计算均线和除权数据
  2. yum工具对软件包安装,删除,更新介绍
  3. Enterprise Library1.0 -- DataAccess Application Block
  4. 《nodejs+gulp+webpack基础实战篇》课程笔记(四)-- 实战演练
  5. java finalize方法的使用
  6. JS之返回指定位置字符的charAt方法
  7. tar+openssl加密压缩解压缩
  8. 如何优雅地抄袭代码?天下代码一大抄,这才是正确的姿势
  9. 信息安全——对称算法与非对称算法
  10. django学习笔记:AdminSite界面配置
  11. 设计师学python还是processing_人人都能学会的processing创意编程能实现什么?
  12. Spice Windows Client 利用 USBDk 实现USB重定向
  13. UNIX编程艺术学习笔记-1
  14. 线性查找与二分查找的平均查找次数的比较
  15. 20 个实例玩转 Java 8 Stream
  16. 【无标题】学生成绩管理系统
  17. Spring源码分析总结(二)-Spring AOP 解析aop:aspectj-autoproxy
  18. 多旋翼油门量与升力关系
  19. 关于四叶玫瑰花数的问题
  20. css加透明边框,CSS3实现透明边框的方法分享

热门文章

  1. BABvsBABAB
  2. 手势识别系统的发展前景
  3. anchor free 目标检测_【目标检测】anchor-free—CenterNet总结
  4. (crm笔记2-2)在前端页面输出后台查询出的表单数据
  5. vue 项目使用 openlayers根据半径绘制圆形、绘制多边形
  6. web页面 新消息提示音
  7. Linux环境下程序的多核CPU占用率高的问题分析和解决
  8. linux设置定时任务(crontab)
  9. 空间规划中的“以流定形”:空间关系-空间活动-空间网络
  10. DRM标准学习笔记1