Sunscreen

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 12907   Accepted: 4534

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

题解:现在有一群奶牛在沙滩上晒太阳,需要涂防晒霜。求所能被防晒的奶牛最多的只数。

输入:1st  两个用空格分开的整数  C L,分别代表 奶牛的头数(cows) 和 防晒霜的 瓶数( lotion )。

2nd 接下来 C行,输入 单只奶牛所需最小的防晒霜的防嗮系数 minSPF ,最大的  maxSPF,每行数据用空格隔开。

3rd 再接下来 L行 ,输入 防晒霜的防晒系数t1 和瓶数 t2  每行数据用空格隔开。

注意:不同行的防晒霜,他们的防晒系数可能一样,所以可以用类似于桶排序中的桶的使用方法 用一个数组来存储防晒霜瓶数,数组下标就是防晒系数。

思路:读入数据->以奶牛的最小防晒系数为关键字 由高到低 排列 奶牛数据所在的结构体数组->循环遍历奶牛:一只奶牛 再遍历最高防晒系数j=maxspf 到最低防晒系数j>=minspf  j-- 查询 (类似于桶排序)防晒霜数组 lo[j],一旦有防晒霜在

这个区间,那么可被防晒的奶牛数量加一,对应的 lo[j]  即防晒系数spf=j 的防晒霜数量减一。条件是这个防晒霜数量不能少于1.

(所以就是贪心)

 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <cstring>
 4
 5 #include <algorithm>
 6 using namespace std;
 7 //bool vis[2509];
 8 struct cow{
 9     int mina;
10     int maxa;
11 }co[2509];
12
13 bool cmpcow(cow x, cow y)
14 {
15         return x.mina>y.mina;
16 }
17 int lo[1009];
18 //bool lotions(lotion x,lotion y)
19 //{
20 //    return x.spf<y.spf;
21 //}
22 int main()
23 {    int c,l;
24         while(scanf("%d%d",&c,&l)!=EOF)
25     {
26
27         int sum=0;
28     //    memset(vis,false,sizeof(vis));
29
30         for(int i=1;i<=c;i++){
31             scanf("%d%d",&co[i].mina,&co[i].maxa);
32         }
33         for(int i=1;i<=l;i++){
34             int t1,t2;
35             scanf("%d%d",&t1,&t2);//type
36 //            scanf("");//quantity
37 //            lo[t1].spf=t1;
38             lo[t1]+=t2;
39         }
40
41         sort(co+1,co+c+1,cmpcow);
42     //    sort(lo,lo+l,lotions);
43
44         for(int i=1;i<=c;i++){
45             for(int j=co[i].maxa;j>=co[i].mina;j--){
46                 if(lo[j])
47                 {
48                     sum++,lo[j]--;
49                     break;
50                 }
51             }
52         }
53
54         printf("%d",sum);
55     }
56     return 0;
57 }

。。。

转载于:https://www.cnblogs.com/greenaway07/p/10662213.html

POJ 3614 Sunscreen相关推荐

  1. 【POJ 3614 Sunscreen】贪心 优先级队列

    题目链接:http://poj.org/problem?id=3614 题意:C头牛去晒太阳,每头牛有自己所限定的spf安全范围[min, max]:有L瓶防晒液,每瓶有自己的spf值和容量(能供几头 ...

  2. poj 3614 Sunscreen(优先队列+贪心)

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

  3. POJ - 3614 Sunscreen(贪心/二分图最大匹配-多重匹配/网络流-最大流)

    题目链接:点击查看 题目大意:给出n头奶牛,奶牛们现在要晒太阳,每头奶牛需要[l,r]区间内的光照强度,现在有m种防晒霜,每种防晒霜可以让奶牛接受到val数值的光照强度,然后每种防晒霜只有num个,现 ...

  4. 【贪心】Sunscreen(poj 3614/luogu 2887)

    Sunscreen poj 3614 luogu 2887 题目大意: 有n个人,每个人要求选一个价值在minniminn_iminni​到maxximaxx_imaxxi​的物品,现在有m件物品,每 ...

  5. poj 3614(最大流)

    Sunscreen Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6682   Accepted: 2350 Descrip ...

  6. 《挑战程序设计竞赛(第2版)》习题册攻略

    本项目来源于GitHub 链接: 项目GitHub链接 1 前言 项目为<挑战程序设计竞赛(第2版)>习题册攻略,已完结.可配合书籍或笔记,系统学习算法. 题量:约200道,代码注释内含详 ...

  7. Kattis - icpccamp ICPC Camp(二分+贪心)

    题目链接:点击查看 题目大意:给出两种种类的数字分别 m1m_1m1​ 和 m2m_2m2​ 个,现在要求匹配 nnn 个不同种类的数字,每个数字只能使用一次,且两数之和不能超过 sss,输出任意两对 ...

  8. $2019$ 暑期刷题记录 $2$(基本算法专题)

    $ 2019 $ 暑期刷题记录 $ 2 $ (基本算法专题) $ by~~wch $ $ BZOJ~1958~Strange~Towers~of~Hanoi $ (动态规划,递推) 题目大意: 求有 ...

  9. css中在图片上加透明,css 给图片添加滤镜效果,透明层毛玻璃效果

    我们用的第一个滤镜是sepia(),他会给图片增加一整降饱和度的橙色染色效果 原图 添加sepia滤镜的效果 img{ width:100%; transition: .5s filter; filt ...

最新文章

  1. [转贴]经济学人:Win7拉开新时代序幕 云计算群雄逐鹿
  2. exchange迁移测试作业
  3. html date 设置时间,JavaScript Date(日期)
  4. CMake3:添加一个库
  5. Hadoop的搭建,VmwareWorkstation 16pro + Ubuntu18.04.1
  6. 重构第12天 分解依赖(Break Dependencies)
  7. React Native之Props(属性)和State(状态)和简单样式简单使用
  8. vue php企业站案例,vue 开发企业微信整合案例分析
  9. php判断一个字符串是否为纯数字,php判断变量是否为纯数字字符串的方法
  10. SELinux入门:了解和配置SELinux
  11. ak和sk怎么认证 海康威视_公有云API的认证方式:AK/SK 简介
  12. 【机器学习-西瓜书】九、聚类:性能度量;距离计算
  13. python推荐系统算法朴素贝叶斯_机器学习经典算法之朴素贝叶斯分类
  14. 图像语义分割(15)-ConvCRFs:用于语义分割的卷积条件随机场
  15. 预知昨天事情不顺,果然碰到两个
  16. 一连三问 !!! 什么是内存对齐?内存对齐的原因是什么?内存对齐的好处是什么?
  17. LTE无线接入网的架构
  18. 嵌入式硬件设计:SoC开发、电源设计、人机交互设计
  19. 不仅仅是一种爱好:了解中国的电竞市场
  20. 物联网(IoT)行业的决策管理应用

热门文章

  1. mysql open table_MySQL open table
  2. 2021年3月15日_读书|总结笔记目录
  3. 玄学········为什么在eclipse上更改程序之后运行之后好像没更改一样
  4. python手动安装包_python pip如何手动安装二进制包
  5. hyper-v虚拟服务器内存满了,在Hyper-V Dynamic Memory里设置虚拟内存
  6. java 2d绘图 stroke_Java标准教程:Java 2D绘图--第4章使用Text
  7. snowflake做主键 自增_自增ID算法snowflake - C#版
  8. react全局方法_前端面试题 ---react
  9. Java封装图书信息类
  10. Spring Boot Data JPA