poj 2376 Cleaning Shifts 贪心
来源:互联网 发布:unix环境高级编程linux 编辑:程序博客网 时间:2024/03/28 17:13
每次选择开头被覆盖的最大的值
#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int maxn=1e6+9;int dp[maxn];int main(){ int n,t; while(scanf("%d %d",&n,&t)!=EOF) { memset(dp,0,sizeof(dp)); for(int i=1,t,s;i<=n;i++) { scanf("%d %d",&s,&t); dp[s-1]=max(dp[s-1],t); } for(int i=1;i<=t;i++) dp[i]=max(dp[i],dp[i-1]); int ans=0,now=0; while(now<t) { if(dp[now]<=now) break; else { ans++; now=dp[now]; } } if(now>=t) cout<<ans<<endl; else cout<<-1<<endl; } return 0;}
- poj 2376 Cleaning Shifts( 贪心 )
- POJ 2376 Cleaning Shifts 贪心
- poj 2376 Cleaning Shifts( 贪心 )
- poj 2376 Cleaning Shifts 贪心
- 贪心-poj 2376-Cleaning Shifts
- POJ 2376 - Cleaning Shifts(贪心)
- Cleaning Shifts - POJ 2376 贪心
- Cleaning Shifts (poj 2376 贪心)
- Cleaning Shifts - POJ 2376 贪心
- [贪心] poj 2376 Cleaning Shifts
- [贪心] poj 2376 Cleaning Shifts
- POJ 2376 Cleaning Shifts [贪心]
- Poj 2376 Cleaning Shifts【贪心】
- POJ 2376 Cleaning Shifts 贪心
- POJ 2376 Cleaning Shifts(贪心)
- POJ 2376 Cleaning Shifts 贪心
- POJ 2376 Cleaning Shifts(贪心)
- 【贪心+排序】poj 2376 Cleaning Shifts
- android侧滑效果,SlidingMenu配置
- 排序算法之冒泡排序的基本介绍和数组越界,以及交换2个变量的3种方法
- MySql引擎
- Ubuntu root下无声音问题
- C++this指针
- poj 2376 Cleaning Shifts 贪心
- iOS☞旋转动画学习总结
- java System类
- mac下如何看凤凰卫视等直播
- 开始使用MASM
- Computer Vision Research Groups
- updating to Android SDK Tools出现问题解决办法
- 励志英语
- 从密码学角度看腾讯常用的TEA加密算法