poj3614 Sunscreen【贪心】
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 11772 | Accepted: 4143 |
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
题意:
有c头牛,每头牛有一个区间。有l种防晒霜,每种有一个spf值和对应的瓶数。牛只能用在他区间内的防晒霜。问最多能有多少牛被涂。
思路:
按minspf排序,每次取minspf最高的一头牛,给他安排可以被安排的spf值最高的防晒霜。
因为我们这样排了序之后,能给minspf高的牛用的防晒霜肯定也能给minspf低一些的牛用。
这时候就要尽量用spf值高的。
#include <iostream>
#include <set>
#include <cmath>
#include <stdio.h>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
//#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define inf 0x7f7f7f7f int c, l;
const int maxn = ;
struct lotion{
int spf;
int cover;
}lo[maxn];
struct mow{
int minspf, maxspf;
}cow[maxn]; bool cmpcow(mow a, mow b)
{
if(a.minspf == b.minspf){
return a.maxspf < b.maxspf;
}
return a.minspf < b.minspf;
} bool cmplo(lotion a, lotion b)
{
return a.spf < b.spf;
} int main()
{
while(scanf("%d%d", &c, &l) != EOF){
for(int i = ; i < c; i++){
scanf("%d%d", &cow[i].minspf, &cow[i].maxspf);
}
//cout<<cow[0].minspf<<" "<<cow[0].maxspf<<endl;
for(int i = ; i < l; i++){
scanf("%d%d", &lo[i].spf, &lo[i].cover);
}
sort(cow, cow + c, cmpcow);
//cout<<cow[0].minspf<<" "<<cow[0].maxspf<<endl;
sort(lo, lo + l, cmplo); int cnt = ;
for(int i = c - ; i >= ; i--){
for(int j = l - ; j >= ; j--){
if(lo[j].spf < cow[i].minspf)break;
if(lo[j].spf <= cow[i].maxspf && lo[j].cover > && lo[j].spf >= cow[i].minspf){
lo[j].cover--;
cnt++;
break;
}
}
}
printf("%d\n", cnt);
}
return ;
}
poj3614 Sunscreen【贪心】的更多相关文章
- [POJ3614]Sunscreen (贪心)
题意 (依然来自洛谷) 有C个奶牛去晒太阳 (1 <=C <= 2500),每个奶牛各自能够忍受的阳光强度有一个最小值和一个最大值,太大就晒伤了,太小奶牛没感觉. 而刚开始的阳光的强度非常 ...
- POJ3614 Sunscreen 贪心入门
题目大意 给出一些区间和一些点,一个点如果在一个区间内,那么此两者可以匹配.问匹配数最大是多少. 题解 这样的题我们一般都是站在区间上去找与其配对的点.我们可以得到如下性质: 对于一段区间\([l_1 ...
- POJ--3614 Sunscreen(贪心)
题目 3614 Sunscreen 2500*2500直接排序暴力贪心 #include<iostream> #include<cstring> #include<alg ...
- poj3614 Sunscreen(贪心+STL)
https://vjudge.net/problem/POJ-3614 如果这不是优先队列专题里的,我可能不一定能想到这么做. 结构体命名得有点不好,解题中看着Edge这个不恰当的命名,思路老是断掉. ...
- POJ3614 Sunscreen 优先队列+贪心
Description To avoid unsightly burns while tanning, each of the C (1 ≤ C ≤ 2500) cows must cover her ...
- 【POJ3614 Sunscreen】【贪心】
题面: 有c头牛,需要的亮度在[min_ci,max_ci]中,有n种药,每种m瓶,可以使亮度变为v 问最多能满足多少头牛 算法 我们自然考虑贪心,我们首先对每头牛的min进行排序,然后对于每种药,将 ...
- POJ 3614 Sunscreen 贪心
题目链接: http://poj.org/problem?id=3614 Sunscreen Time Limit: 1000MSMemory Limit: 65536K 问题描述 to avoid ...
- POJ 3614:Sunscreen 贪心+优先队列
Sunscreen Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5378 Accepted: 1864 Descrip ...
- poj -3614 Sunscreen(贪心 + 优先队列)
http://poj.org/problem?id=3614 有c头奶牛在沙滩上晒太阳,每头奶牛能忍受的阳光强度有一个最大值(max_spf) 和最小值(min_spf),奶牛有L种防晒霜,每种可以固 ...
随机推荐
- MsChart,饼状图
HTML 后台代码:(dt为数据源)数据库中数据Sample 1 Chart1.Series["Series1"].Label = "#PERCENT{P}"; ...
- Android刮刮卡效果
不多说,直接上代码: package com.example.test; import android.app.Activity; import androi ...
- 一致性Hash算法原理及C#代码实现
一.一致性Hash算法原理 基本概念 一致性哈希将整个哈希值空间组织成一个虚拟的圆环,如假设某哈希函数H的值空间为0-2^32-1(即哈希值是一个32位无符号整形),整个哈希空间环如下: 整个空间按顺 ...
- Oracle批量执行SQL语句
SQLServer的场合,用";"分割SQL语句即可正常执行. Oracle的场合,会报ORA-00911错误.Oracle中需要加上begin end才正确. Dim Sql A ...
- Windows Server 2008 + SQL Server 2005集群
一. 基础环境 1. 服务器规划 2. 网络拓扑 二. 相关说明 1.为了节约服务器资源,AD服务器可以和iSCSI设备服务器同为一台服务器.由于iSCSI软件需要,目前微软只开发了基于Windows ...
- Dubbo -- 系统学习 笔记 -- 示例 -- 泛化引用
Dubbo -- 系统学习 笔记 -- 目录 示例 想完整的运行起来,请参见:快速启动,这里只列出各种场景的配置方式 泛化引用 泛接口调用方式主要用于客户端没有API接口及模型类元的情况,参数及返回值 ...
- 【代码审计】Cscms_v4.1 任意文件删除漏洞实例
环境搭建: CSCMS :http://www.chshcms.com/ 网站源码版本:Cscms_v4.1正式版(发布日期:2017-06-05) 程序源码下载:https://github.com ...
- MongoDB(五)-- 副本集(replica Set)
一.副本集介绍 搭建副本集是为了实现mongodb高可用. Mongodb(M)表示主节点,Mongodb(S)表示备节点,Mongodb(A)表示仲裁节点.主备节点存储数据,仲裁节点不存储数据.客户 ...
- N76E003的学习之路(一)
N76E003是8051内核的一款单片机MCU,它提供丰富的特殊功能模块,包括: 1KRAM其中包括256字节SRAM,768字节XRAM. 最多可达18个标准管脚. 两组标准16位定时器/计数器:定 ...
- linux下使用ftp传递文件的shell脚本
使用ftp传递文件,传递过程中防止对方取文件,后缀名为writing,传完后再改回来. #!/bin/bash dstpath=cnet ftpip="127.0.0.1" log ...