贪心题。

如何找出正确的贪心策略呢?

我一开始是以为按照l排序,然后从1到n遍历,挑最大的满足的防晒霜。后来发现不行。挑最小的也不行。

看了题解发现是从n到1遍历。

为什么?

因为i-1的l比i的l承受能力要大些,我们只需考虑r!

而i+1的l比i的l承受能力要小一些!我们要两头考虑!失败!

然后是一些实现小细节了,包括手写二分......

 #include <cstdio>
#include <algorithm>
/// poj 3614
using namespace std;
const int N = ;
int n, L;
struct Cow{
int a, b;
bool operator < (const Cow &x) const {
if(this->a != x.a) {
return this->a < x.a;
}
return this->b < x.b;
}
}c[N], a[N];
int main() {
scanf("%d%d", &n, &L);
for(int i = ; i <= n; i++) {
scanf("%d%d", &c[i].a, &c[i].b);
}
for(int i = ; i <= L; i++) {
scanf("%d%d", &a[i].a, &a[i].b);
}
sort(c + , c + n + );
sort(a + , a + L + );
int ans = ;
a[L + ].a = 0x7f7f7f7f;
/*
printf("\n");
for(int i = 1; i <= n; i++) {
printf("%d %d\n", c[i].a, c[i].b);
}
printf("\n");
for(int i = 1; i <= L + 1; i++) {
printf("%d %d\n", a[i], sum[i]);
}
printf("\n");
*/
for(int i = n; i >= ; i--) {
int p, l = , r = L + ;
while(l < r) {
p = (l + r) >> ;
if(a[p].a <= c[i].b) {
l = p + ;
}
else r = p;
}
if(a[p].a > c[i].b) p--;
//printf("%d ", p);
while(!a[p].b && a[p].a >= c[i].a) {
p--;
}
//printf("%d\n", p);
if(p && a[p].a <= c[i].b && a[p].a >= c[i].a) {
ans++;
a[p].b--;
}
}
printf("%d", ans);
return ;
}

AC代码

poj3614 Sunscreen的更多相关文章

  1. POJ3614 Sunscreen 优先队列+贪心

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

  2. POJ--3614 Sunscreen(贪心)

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

  3. poj3614 Sunscreen(贪心+STL)

    https://vjudge.net/problem/POJ-3614 如果这不是优先队列专题里的,我可能不一定能想到这么做. 结构体命名得有点不好,解题中看着Edge这个不恰当的命名,思路老是断掉. ...

  4. poj3614 Sunscreen【贪心】

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

  5. [POJ3614]Sunscreen (贪心)

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

  6. POJ3614 Sunscreen 贪心入门

    题目大意 给出一些区间和一些点,一个点如果在一个区间内,那么此两者可以匹配.问匹配数最大是多少. 题解 这样的题我们一般都是站在区间上去找与其配对的点.我们可以得到如下性质: 对于一段区间\([l_1 ...

  7. 【POJ3614 Sunscreen】【贪心】

    题面: 有c头牛,需要的亮度在[min_ci,max_ci]中,有n种药,每种m瓶,可以使亮度变为v 问最多能满足多少头牛 算法 我们自然考虑贪心,我们首先对每头牛的min进行排序,然后对于每种药,将 ...

  8. POJ3614 [USACO07NOV]防晒霜Sunscreen

    Sunscreen Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9333   Accepted: 3264 Descrip ...

  9. Sunscreen [POJ3614] [贪心]

    描述 C (1 ≤ C ≤ 2500) 头奶牛在海滩边晒太阳,要避免在日光浴时产生难看的灼伤,每头奶牛必须用防晒霜覆盖它的皮肤.第 i 头奶牛有一个最小和最大 SPF 值 (1 ≤ minSPFi ≤ ...

随机推荐

  1. jQuery操作复选框checkbox技巧总结 ---- 设置选中、取消选中、获取被选中的值、判断是否选中等

    转载:https://blog.csdn.net/chenchunlin526/article/details/77448168 jQuery操作复选框checkbox技巧总结 --- 设置选中.取消 ...

  2. 转:win7下git凭据导致无法clone代码

    win7下存在一个凭据管理的情况,如果旧凭据没有删除,用新账户是无法clone代码的. https://blog.csdn.net/qq_34665539/article/details/804082 ...

  3. sonar安装

    ##jdk不要用yum下载的 一.下载sonar源码 cd /usr/local/src wget https://sonarsource.bintray.com/Distribution/sonar ...

  4. scrapy的一些容易忽视的点(模拟登陆,传递item等)

    scrapy爬虫注意事项 一.item数据只有最后一条 这种情况一般存在于对标签进行遍历时,将item对象放置在了for循环的外部.解决方式:将item放置在for循环里面.   二.item字段传递 ...

  5. IWMS后台上传文章,嵌入音频文件代码

    <object width="260" height="69" classid="clsid:6bf52a52-394a-11d3-b153-0 ...

  6. Http请求笔记

    1 HTTP请求报文组成: 请求行:请求方法 url 协议版本 请求头:报文头-属性名:属性值 Accept属性告诉服务端-客户端接受什么类型的响应,可为一个或多个mime类型值 Cookie:服务端 ...

  7. VS2017设置背景主题

    一.VS2017设置背景主题 1.下载并安装Color Theme Editor for Visual Studio 2017和MoeIDE (图中红圈中的两个插件,工具-扩展和更新-联机-右上角搜索 ...

  8. How to execute a Stored Procedure with Entity Framework Code First

    Recently I worked on a project, which I started as code first and then I forced to switch to Databas ...

  9. [Codeforces266E]More Queries to Array...——线段树

    题目链接: Codeforces266E 题目大意:给出一个序列$a$,要求完成$Q$次操作,操作分为两种:1.$l,r,x$,将$[l,r]$的数都变为$x$.2.$l,r,k$,求$\sum\li ...

  10. 前端 -- CSS基础

    一,CSS介绍 CSS(Cascading Style Sheet,层叠样式表)定义如何显示HTML元素. 当浏览器读到一个样式表,它就会按照这个样式表来对文档进行格式化(渲染). 二,CSS语法 1 ...