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(区间贪心,理解题意)的更多相关文章

  1. poj2376 Cleaning Shifts 区间贪心

    题目大意: (不说牛了) 给出n个区间,选出个数最少的区间来覆盖区间[1,t].n,t都是给出的. 题目中默认情况是[1,x],[x+1,t]也是可以的.也就是两个相邻的区间之间可以是小区间的右端与大 ...

  2. POJ2376 Cleaning Shifts 【贪心】

    Cleaning Shifts Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11542   Accepted: 3004 ...

  3. POJ2376 Cleaning Shifts

    题意 POJ2376 Cleaning Shifts 0x50「动态规划」例题 http://bailian.openjudge.cn/practice/2376 总时间限制: 1000ms 内存限制 ...

  4. 【POJ - 2376】Cleaning Shifts(贪心)

    Cleaning Shifts Descriptions: 原文是English,我这就直接上Chinese了,想看原文的点一下链接哦 大表哥分配 N (1 <= N <= 25,000) ...

  5. poj 3171 Cleaning Shifts(区间的最小覆盖价值)

    Cleaning Shifts Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2743   Accepted: 955 De ...

  6. poj2376 Cleaning Shifts【线段树】【DP】

    Cleaning Shifts Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 32561   Accepted: 7972 ...

  7. poj-2376 Cleaning Shifts (排序+贪心)

    http://poj.org/problem?id=2376 john有n头牛做打扫工作,他想在t时间内每个时间都至少有一头牛在做打扫工作,第一头牛在1,最后一头牛在t时间,每一头牛工作都有一个开始时 ...

  8. poj 2376 Cleaning Shifts(贪心)

    Description Farmer John <= N <= ,) cows to <= T <= ,,), the first being shift and the la ...

  9. ACM学习历程——POJ 2376 Cleaning Shifts(贪心)

    Description Farmer John is assigning some of his N (1 <= N <= 25,000) cows to do some cleaning ...

随机推荐

  1. ubuntu系统安装mysql登陆提示 解决Mysql ERROR 1045 (28000): Access denied for user 'root'@'localhost'问题

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAqoAAABtCAIAAADmldQYAAAe/0lEQVR4nO1dveslR3btzJGFk02GmU

  2. Zabbix监控Low level discovery实时监控网站URL状态

    今天我们来聊一聊Low level discovery这个功能,我们为什么要用到loe level discovery这个功能呢? 很多时候,在使用zabbix监控一些东西,需要对类似于Itens进行 ...

  3. 搜狐JS查ip

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. Codeforces 802I Fake News (hard) (SA+单调栈) 或 SAM

    原文链接http://www.cnblogs.com/zhouzhendong/p/9026184.html 题目传送门 - Codeforces 802I 题意 求一个串中,所有本质不同子串的出现次 ...

  5. VS2017 cdkey

    Enterprise:NJVYC-BMHX2-G77MM-4XJMR-6Q8QF ProfessionalKBJFW-NXHK6-W4WJM-CRMQB-G3CDH

  6. Java字符串处理

    代码: import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner s ...

  7. POJ 2594 Treasure Exploration (Floyd+最小路径覆盖)

    <题目链接> 题目大意: 机器人探索宝藏,有N个点,M条边.问你要几个机器人才能遍历所有的点. 解题分析: 刚开始还以为是最小路径覆盖的模板题,但是后面才知道,本题允许一个点经过多次,这与 ...

  8. Anaconda 虚拟环境的使用

    目录 前言 1. 创建虚拟环境 2. 虚拟环境管理 3. Conda虚拟环境的包管理 前言 今天把anaconda进行了滚动更新,实体环境python版本也相应从3.6跟新到了3.7.但是问题来了,之 ...

  9. spring注解工具类AnnotatedElementUtils和AnnotationUtils

    一.前言 spring为开发人员提供了两个搜索注解的工具类,分别是AnnotatedElementUtils和AnnotationUtils.在使用的时候,总是傻傻分不清,什么情况下使用哪一个.于是我 ...

  10. Qt程序继承QApplication发生崩溃的原因

    一.前情介绍 QApplication是Qt开发中经常用到的一个类,用来管理应用程序的生命周期.跟其相关的类还有QCoreApplication和QGuiApplication,分别用于不同场景下为应 ...