poj3614 贪心
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 6410 | Accepted: 2239 |
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
题目大意:具体单词我也不太懂,不过大体意思就是每一只奶牛都有着需要的spf最大值和最小值,然后现在有一些类似防晒霜
可以提供spf,如果一只奶牛被保护,意思就是涂的防晒液提供的spf刚好在要求的最大值和最小值之间,问你最多能保护度多
少只奶牛。
思路分析:目前我只会用贪心做,很显然,需要进行排序,但是是按照最大值还是最小值排序呢,用最小值排序很容易举出反例,
按最大值排序的时候很多情况都是符合的,防晒液按照能够提供的spf从小到大排序是毫无疑问的,然后遍历走一遍就能求出最多
的奶牛数了。
讲道理真让我证明我也不会,但是感觉是这样,也许这就是贪心的精髓吧,在没有其他思路的情况下贪心往往能有奇妙的作用。
另外,要细心!!!内层循环j写成了iwa了四发,555555555555.
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;
const int maxn=2500+10;
struct nod
{
int a;
int b;
};
nod cow[maxn],s[maxn];
bool cmp1(nod x,nod y)
{
return x.b==y.b?x.a<y.a:x.b<y.b;
}
bool cmp2(nod x,nod y)
{
return x.a<y.a;
}
int main()
{
int c,l;
int m,n;
while(scanf("%d%d",&c,&l)!=EOF)
{
for(int i=0;i<c;i++)
{
scanf("%d%d",&cow[i].a,&cow[i].b);
}
for(int i=0;i<l;i++)
{
scanf("%d%d",&s[i].a,&s[i].b);
}
sort(cow,cow+c,cmp1);
sort(s,s+l,cmp2);
int cut=0;
for(int i=0;i<c;i++)
{
for(int j=0;j<l;j++)
{
if(s[j].a>=cow[i].a&&s[j].a<=cow[i].b&&s[j].b>0)
{
cut++;
s[j].b--;
break;
}
}
}
cout<<cut<<endl;
}
return 0;
}
poj3614 贪心的更多相关文章
- POJ3614 贪心+优先队列
题意:m头牛每头牛有minspf和maxspf,n种spf为spf[i]的防晒霜每种l[i]瓶,尽可能给数量多的牛涂防晒霜,每头牛最多涂一瓶. 思路:贪心想法,实现是每次取出minspf<=sp ...
- Sunscreen [POJ3614] [贪心]
描述 C (1 ≤ C ≤ 2500) 头奶牛在海滩边晒太阳,要避免在日光浴时产生难看的灼伤,每头奶牛必须用防晒霜覆盖它的皮肤.第 i 头奶牛有一个最小和最大 SPF 值 (1 ≤ minSPFi ≤ ...
- poj3614 Sunscreen(贪心+STL)
https://vjudge.net/problem/POJ-3614 如果这不是优先队列专题里的,我可能不一定能想到这么做. 结构体命名得有点不好,解题中看着Edge这个不恰当的命名,思路老是断掉. ...
- POJ--3614 Sunscreen(贪心)
题目 3614 Sunscreen 2500*2500直接排序暴力贪心 #include<iostream> #include<cstring> #include<alg ...
- [POJ3614]Sunscreen (贪心)
题意 (依然来自洛谷) 有C个奶牛去晒太阳 (1 <=C <= 2500),每个奶牛各自能够忍受的阳光强度有一个最小值和一个最大值,太大就晒伤了,太小奶牛没感觉. 而刚开始的阳光的强度非常 ...
- POJ3614 Sunscreen 贪心入门
题目大意 给出一些区间和一些点,一个点如果在一个区间内,那么此两者可以匹配.问匹配数最大是多少. 题解 这样的题我们一般都是站在区间上去找与其配对的点.我们可以得到如下性质: 对于一段区间\([l_1 ...
- POJ3614防晒霜 这个贪心有点东西(贪心+优先队列)
这个题是说有C头牛去晒太阳,带了L瓶防晒霜,每瓶防晒霜都有一个SPF值(每瓶防晒霜都能解决一个最短路 ) 每头牛给出了他可以接受防晒霜的上限,和下限,每种防晒霜都给出了SPF值与数量. 从防晒霜的sp ...
- POJ3614奶牛晒阳光DINIC或者贪心
题意: n个区间,m种点,每种点有ci个,如果一个点的范围在一个区间上,那么就可以消耗掉一个区间,问最多可以消耗多少个区间,就是这n个区间中,有多少个可能被抵消掉. 思路: 方 ...
- 【POJ3614 Sunscreen】【贪心】
题面: 有c头牛,需要的亮度在[min_ci,max_ci]中,有n种药,每种m瓶,可以使亮度变为v 问最多能满足多少头牛 算法 我们自然考虑贪心,我们首先对每头牛的min进行排序,然后对于每种药,将 ...
随机推荐
- 解读CSS文本(text)样式
通过文本属性,您可以改变文本的颜色.字符间距.对齐文本.装饰文本.文本缩进,等等. color: 该属性用于改变文本的颜色,注意区分background-color. Line-height: 该属性 ...
- CentOS7.1 使用资源搜集
1.配置java环境 -openjdk* 测试 java -version 2.安装Tomcat8.0.35 点击题目可以参考源网页,但有些代码无法执行,更改如下(亲测可行): 一定要先安装java环 ...
- JSP中页面定时刷新
1.JSP中页面定时刷新 <% //页面每隔30秒自动刷新一遍 response.setHeader("refresh" , "30" ); %> ...
- js 当前系统时间
<script language=Javascript> function time(){ //获得显示时间的div t_div = document.getElementById('sh ...
- Dede文章列表
文章列表标签的使用: {dede:arclist flag='h' typeid='' row='' col='' titlelen='' infolen='' imgwidth='' imgheig ...
- libevent入门(1)
libevent是什么 libevent 库实际上没有更换 select().poll() 或其他机制的基础.而是使用对于每个平台最高效的高性能解决方案在实现外加上一个包 ...
- production stage
MP:mass production 批量生产 DV design verification 设计验证 EV engineering verification 工程样品验证 PV process ve ...
- Spring MVC 和Struts2对比
Spring MVC和Struts2的区别: 1. 机制:spring mvc的入口是servlet,而struts2是filter,这样就导致了二者的机制不同. 2. 性能:spring会稍微比s ...
- Delphi - GetUserNameEx(学一下导出Windows API,以及Array Char充当缓冲区的用法,下标必须从零开始)
(* * Author : http://www.michael-puff.de * Date : 2006-03-29 * License : PUBLIC DOMAIN *) function G ...
- MVC4.0 上传Excel并存入数据库
这里的这个功能实现在WebForm很好实现,上传阶段简单的一个FileUoLoad控件就搞定了,什么取值,什么上传都是浮云,微软都帮我们封装好了,我们只需要一拖一拽就OK了,但这些在MVC中是不行的! ...