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

  1. 3 2
  2. 3 10
  3. 2 5
  4. 1 5
  5. 6 2
  6. 4 1

Sample Output

  1. 2

Source

 
【题解】
把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 = + ;
  9.  
  10. inline void read(int &x)
  11. {
  12. x = ;char ch = getchar(),c = ch;
  13. while(ch < '' || ch > '')c = ch, ch = getchar();
  14. while(ch <= '' && ch >= '')x = x * + ch - '', 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 = ;i <= C;++ i) read(l[i]), read(r[i]), cnt[i] = i;
  35. for(register int i = ;i <= L;++ i) read(point[i]), read(num[i]), cntt[i] = i;
  36. std::sort(cnt + , cnt + + C, cmp);
  37. std::sort(cntt + , cntt + + L, cmpp);
  38. for(register int i = ;i <= C;++ i)
  39. {
  40. for(register int j = ;j <= L;++ j)
  41. if(num[cntt[j]] > && 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 ;
  50. }

POJ3614

POJ3614 [USACO07NOV]防晒霜Sunscreen的更多相关文章

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

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

  2. 洛谷P2877 [USACO07NOV]防晒霜Sunscreen

    题目 此题有多种贪心方法. 首先简化题意: 有几个在数轴上的区间,和几个在数轴上确定的位置的点,问用这些数目的点,最多能满足多少个区间里有点. 注意:此题跟区间选点问题不一样,每个点只能满足一个区间, ...

  3. 洛谷 - P2887 - 防晒霜Sunscreen - 贪心

    https://www.luogu.org/problemnew/show/P2887 感觉可以: 把防晒霜拆点限制流量为瓶数,奶牛拆点限制流量为1,当某个防晒霜与奶牛匹配时连一条边,求最大流.但是这 ...

  4. ImageNet2017文件下载

    ImageNet2017文件下载 文件说明 imagenet_object_localization.tar.gz包含训练集和验证集的图像数据和地面实况,以及测试集的图像数据. 图像注释以PASCAL ...

  5. ImageNet2017文件介绍及使用

    ImageNet2017文件介绍及使用 文件说明 imagenet_object_localization.tar.gz包含训练集和验证集的图像数据和地面实况,以及测试集的图像数据. 图像注释以PAS ...

  6. POJ3614 Sunscreen 优先队列+贪心

    Description To avoid unsightly burns while tanning, each of the C (1 ≤ C ≤ 2500) cows must cover her ...

  7. poj3614 Sunscreen【贪心】

    Sunscreen Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11772   Accepted: 4143 Descri ...

  8. 题解 洛谷 P2287 [USACO07NOV]Sunscreen G

    原题 传送门 有C个奶牛去晒太阳 (1 <=C <= 2500),每个奶牛各自能够忍受的阳光强度有一个最小值和一个最大值(minSPFi and maxSPFi),太大就晒伤了,太小奶牛没 ...

  9. POJ--3614 Sunscreen(贪心)

    题目 3614 Sunscreen 2500*2500直接排序暴力贪心 #include<iostream> #include<cstring> #include<alg ...

随机推荐

  1. 后缀自动机SAM

    某神犇:"初三还不会后缀自动机,那就退役吧!" 听到这句话后,我的内心是崩溃的. 我还年轻,我还不想退役--于是,我在后来,努力地学习后缀自动机. 终于,赶在初三开学前,我终于学会 ...

  2. 洛谷 P2886 [USACO07NOV]牛继电器Cow Relays

    题面 解题思路 ## floyd+矩阵快速幂,跟GhostCai爷打赌用不用离散化,最后完败..GhostCai真是tql ! 有个巧妙的方法就是将节点重新编号,因为与节点无关. 代码 #includ ...

  3. Linux清除磁盘上的RAID信息(Disk /dev/mapper/ddf1_4c53492....)

    本文摘自https://www.cnblogs.com/blkqyd/p/7011104.html自学留存 原因: 这是因为硬盘带有raid信息,拿二手硬盘插入服务器时,系统会根据残留的信息自动发现r ...

  4. xshell 连接 kali

    1   修改配置文件 vi /etc/ssh/sshd_config #PasswordAuthentication no 去掉#,并且将no修改为YES //kali中默认是yes PermitRo ...

  5. [转载] OpenCV2.4.3 CheatSheet学习(二)

    二.矩阵操作(拷贝.洗牌.局部访问): src.copyTo(dst) 把src矩阵中的数据拷贝到dst. src.convertTo(dst, type,scale, shift) 缩放并转换到另外 ...

  6. python 可迭代对象,迭代器,生成器的区别及使用

    可迭代对象 可迭代对象类型:list,dict,tuple,str,set,deque等 如何判断一个对象是否是可迭代对象,可以通过dir()方法看它里面有没有__iter__方法,如果有这个方法就是 ...

  7. springboot 2 Hikari 多数据源配置问题(dataSourceClassName or jdbcUrl is required)

    springboot 2 Hikari 多数据源配置问题(dataSourceClassName or jdbcUrl is required) 最近在项目中想试一下使用 Hikari 连接池,以前用 ...

  8. jquery判断元素是否出现在可视区

      在我们的日常开发中,经常会遇到当元素出现在可视区的时候需要去出发某一事件的情况.我最近在优化环球网首页的时候,将非可视区的代码全部放入到webComponent中.打算当这个元素出现在可视区的时候 ...

  9. win7旗舰版64位搭建FTP服务器

    1.安装IIS组件:点击开始菜单->选择控制面板->程序->打开或关闭WINDOWS功能->展开Internet信息服务,勾选FTP服务器(包括FTP服务和FTP扩展性),展开 ...

  10. 【python之路26】字符串之格式化%和format

    Python基础之杂货铺   字符串格式化 Python的字符串格式化有两种方式: 百分号方式.format方式 百分号的方式相对来说比较老,而format方式则是比较先进的方式,企图替换古老的方式, ...