poj2376(贪心)
来源:互联网 发布:初中全程辅导软件下载 编辑:程序博客网 时间:2024/05/07 20:51
题意:问有N头牛,每头牛的工作时间不同,要工作T小时,最少需要几头牛工作。
题意:即是:输入 n 个区间和 t,接着输入 n 个区间[s, e],题意:要求找出最少的区间数覆盖区间目标区间[1, t];
贪心区间问题。。。。。。
#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>using namespace std;#define N 25005struct Range{ int l,r; bool operator <(const Range temp)const{ return l<temp.l; }}ra[N];int main(){ int n,t; while(scanf("%d%d",&n,&t)!=EOF){ for(int i=0;i<n;i++) scanf("%d%d",&ra[i].l,&ra[i].r); sort(ra,ra+n); if(ra[0].l>1){//之前写成if(ra[i].l>1||ra[i].r<t),WA了n次都没发现。。。。终于找出来了 printf("-1\n"); continue; } int i=0,j,pos,ok=0,cnt=1; while(i<n){ if(ra[i].r>=t) {ok=1;break;} pos=i; for(j=i+1;j<n;j++){ if(ra[i].r+1<ra[j].l) break; if(ra[pos].r<ra[j].r) pos=j; }if(i==pos) break; i=pos; cnt++; } printf("%d\n",ok?cnt:-1); }//while return 0;}
0 0
- poj2376(贪心)
- POJ2376--Cleaning Shifts(贪心)
- POJ2376 Cleaning Shifts (贪心)
- poj2376 贪心
- 贪心:POJ2376
- POJ2376(贪心)
- poj2376(贪心)
- poj2376 快排+贪心
- 0.9poj2376(贪心)
- POJ2376 Cleaning Shifts 贪心
- poj2376 Cleaning Shifts 贪心
- POJ2376 Cleaning Shifts(贪心)
- POJ2376 Cleaning Shifts 【贪心】
- poj2376区间贪心
- poj2376(贪心+快排)
- POJ2376贪心Cleaning Shifts
- poj2376 贪心算法
- POJ2376 Cleaning Shifts(贪心)
- USB鼠标驱动框架结构
- 离职总结 | 如何做个好员工?
- next_permutation函数
- Java笔试选择题 1
- HDU - 3033 I love sneakers!(有限制的背包)
- poj2376(贪心)
- 中缀式变为后缀式
- POJ 1330 Nearest Common Ancestors(LCA)
- DirectX11 多重纹理
- shiro学习(二) Realm
- 提取 字符串中 数字
- android PorterDuffXfermode、PorterDuff.Mode 使用
- linq排序
- 端口扫描基础