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 ...
随机推荐
- machinekey生成工具 v1.0 官方最新版
http://www.33lc.com/soft/66056.html 电信下载 广东电信下载 厦门电信下载 湖北电信下载 江苏电信下载 网通下载 陕西网通下载 山东网通下载 甘肃网通下载 山西网通下 ...
- weblogic弱密码检测
http://www.secbox.cn/hacker/tools/6252.html http://60.12.168.73:8088/console/login/LoginForm.jsp htt ...
- Kudu的集群安装(1.6.0-cdh5.14.0)
kudu的架构体系 下图显示了一个具有三个 master 和多个 tablet server 的 Kudu 集群,每个服务器都支持多个 tablet.它说明了如何使用 Raft 共识来允许 maste ...
- sparkStreaming消费kafka-1.0.1方式:direct方式(存储offset到zookeeper)-- 2
参考上篇博文:https://www.cnblogs.com/niutao/p/10547718.html 同样的逻辑,不同的封装 package offsetInZookeeper /** * Cr ...
- Berlekamp-Massey算法简单介绍
请阅读本文的同学们注意:之前这篇博客和所附代码有点问题,求的不一定是最短递推式,非常抱歉 看毛爷爷的论文大概断断续续看了一个月了,看得不是很懂,google了一波好像很快就看懂了,就先口胡一下这个算法 ...
- 简单的线程Thread使用
static void Main(string[] args) { for (int i = 0; i < 5; i++) { aa a = new aa(); a.age = i; Threa ...
- windows配置tomcat https访问
主要参考两篇: http://blog.csdn.net/minute_man/article/details/53787682 http://blog.csdn.net/chow__zh/artic ...
- Maya cmds filterExpand 列出 选择的 uvs vertices faces edges 等 component 类型
Maya cmds filterExpand 列出 选择的 uvs vertices faces edges 等 component 类型 cmds.ls() 的 flags 中没有指明 uvs 等这 ...
- jquery模拟form表单提交并新打开页面
/** * form表单提交本页面打开 * @param url * @param params */ function postCurrent(url,params){ var form = $(& ...
- There is no setter for property named 可能产生的原因!
There is no setter for property named 'operateIP ' in 'class com.chinaunicom.wsp.facade.entity.User ...