poj2376 Cleaning Shifts(区间贪心,理解题意)
https://vjudge.net/problem/POJ-2376
题意理解错了!!真是要仔细看题啊!!
看了poj的discuss才发现,如果前一头牛截止到3,那么下一头牛可以从4开始!!!
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<set>
#define INF 0x3f3f3f3f
typedef long long ll;
using namespace std;
typedef struct{
int x, y;
}Node;
Node node[];
bool cmp(const Node a, const Node b)
{
if(a.x != b.x)
return a.x<b.x;
else
return a.y>b.y;
}//起点相同则返回终点大的,否则返回起点小的
int main()
{
int n, t, cnt=, flag=;
cin >> n >> t;
for(int i = ; i < n; i++){
cin >> node[i].x >> node[i].y;
}
sort(node, node+n, cmp);
if(node[].x != ){
cout << "-1" << endl;
return ;
}
else if(node[].y == t){
cout << "" << endl;
return ;
}
else {
int end = node[].y, pre, maxm = node[].y;
for(int i = ; i < n; i++){
pre = maxm;
while(i < n&&node[i].x<=end+){//这里理解错了!!
if(maxm < node[i].y){
maxm = node[i].y;
}
i++;
}
i--;
//cout << maxm << endl;
if(maxm == t){
cnt++;
flag=;
break;
}
else if(pre == maxm){
break;
}
else{
end = maxm;
cnt++;
}
}
if(!flag) cout << "-1" << endl;
else
cout << cnt << endl;
}
return ;
}
poj2376 Cleaning Shifts(区间贪心,理解题意)的更多相关文章
- poj2376 Cleaning Shifts 区间贪心
题目大意: (不说牛了) 给出n个区间,选出个数最少的区间来覆盖区间[1,t].n,t都是给出的. 题目中默认情况是[1,x],[x+1,t]也是可以的.也就是两个相邻的区间之间可以是小区间的右端与大 ...
- POJ2376 Cleaning Shifts 【贪心】
Cleaning Shifts Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11542 Accepted: 3004 ...
- POJ2376 Cleaning Shifts
题意 POJ2376 Cleaning Shifts 0x50「动态规划」例题 http://bailian.openjudge.cn/practice/2376 总时间限制: 1000ms 内存限制 ...
- 【POJ - 2376】Cleaning Shifts(贪心)
Cleaning Shifts Descriptions: 原文是English,我这就直接上Chinese了,想看原文的点一下链接哦 大表哥分配 N (1 <= N <= 25,000) ...
- poj 3171 Cleaning Shifts(区间的最小覆盖价值)
Cleaning Shifts Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2743 Accepted: 955 De ...
- poj2376 Cleaning Shifts【线段树】【DP】
Cleaning Shifts Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 32561 Accepted: 7972 ...
- poj-2376 Cleaning Shifts (排序+贪心)
http://poj.org/problem?id=2376 john有n头牛做打扫工作,他想在t时间内每个时间都至少有一头牛在做打扫工作,第一头牛在1,最后一头牛在t时间,每一头牛工作都有一个开始时 ...
- poj 2376 Cleaning Shifts(贪心)
Description Farmer John <= N <= ,) cows to <= T <= ,,), the first being shift and the la ...
- ACM学习历程——POJ 2376 Cleaning Shifts(贪心)
Description Farmer John is assigning some of his N (1 <= N <= 25,000) cows to do some cleaning ...
随机推荐
- Tomcat模型结构
一.请求过程 Tomca的两大组件:Connecter和Container Connecter组件 1.Connecter将在某个指定的端口上侦听客户请求,接收浏览器的发过来的 tcp 连接请求,创建 ...
- tjoi2018
1.[TJOI2018]数学计算 傻逼题 会发现符合线段树分治的特点 每个数的操作范围都是连续的 然后就等于区间修改了 #include <bits/stdc++.h> using nam ...
- Introduction to boundary integral equations in BEM
Boundary element method (BEM) is an effective tool compared to finite element method (FEM) for resol ...
- 从oracle导出数据成csv,将csv导入mongodb问题
- Python 实现红绿灯
一.通过Event来实现两个或多个线程间的交互,下面是一个红绿灯的例子,即起动一个线程做交通指挥信号灯,一个线程做车辆,车辆行驶按红灯停,绿灯行的规则. #!/usr/bin/python # -*- ...
- Python自用笔记
函数:raw_input()和input() 注意:在python3.x中,已经删除raw_input(),取而代之的是input(),当然这仅仅是重命名,用法还是一样.因此在这里介绍的是python ...
- docker删除名字为none的imgae
docker rmi $(docker images -f "dangling=true" -q)
- Machine Learning 神器 - sklearn
Sklearn 官网提供了一个流程图, 蓝色圆圈内是判断条件,绿色方框内是可以选择的算法: 从 START 开始,首先看数据的样本是否 >50,小于则需要收集更多的数据. 由图中,可以看到算法有 ...
- AspectJ(AOP)切面获取参数名称和参数
@Async @AfterReturning(value ="execution(public * com.zhx.recharge.service.RechargeService.buil ...
- Java中System类的相关应用
1.Runtime: public class RuntimeDemo { public static void main(String[] args) { Runtime runtime=Runti ...