国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

POJ2376-Cleaning Shifts-區(qū)間貪心

2019-11-08 18:27:58
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

原題鏈接 Cleaning Shifts Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 19831 Accepted: 5047 Description

Farmer John is assigning some of his N (1 <= N <= 25,000) cows to do some cleaning chores around the barn. He always wants to have one cow working on cleaning things up and has divided the day into T shifts (1 <= T <= 1,000,000), the first being shift 1 and the last being shift T.

Each cow is only available at some interval of times during the day for work on cleaning. Any cow that is selected for cleaning duty will work for the entirety of her interval.

Your job is to help Farmer John assign some cows to shifts so that (i) every shift has at least one cow assigned to it, and (ii) as few cows as possible are involved in cleaning. If it is not possible to assign a cow to each shift, PRint -1. Input

Line 1: Two space-separated integers: N and T

Lines 2..N+1: Each line contains the start and end times of the interval during which a cow can work. A cow starts work at the start time and finishes after the end time. Output

Line 1: The minimum number of cows Farmer John needs to hire or -1 if it is not possible to assign a cow to each shift. Sample Input

3 10 1 7 3 6 6 10 Sample Output

2 Hint

This problem has huge input data,use scanf() instead of cin to read data to avoid time limit exceed.

INPUT DETAILS:

There are 3 cows and 10 shifts. Cow #1 can work shifts 1..7, cow #2 can work shifts 3..6, and cow #3 can work shifts 6..10.

OUTPUT DETAILS:

By selecting cows #1 and #3, all shifts are covered. There is no way to cover all the shifts using fewer than 2 cows. Source

USACO 2004 December Silver

#include <cstdio>#include <iostream>#include <algorithm>using namespace std;const int maxn=25000 + 10;const int maxlen=1000000 + 10;typedef pair<int,int> P;P p[maxn];int n,len;bool cmp(P x,P y){ return x.first < y.first;}int solve(int can,int latest,int num){ if(latest >= len) return num; int begin = latest +1; //找到從begin開(kāi)始工作的工作時(shí)間最晚的牛 for(int i=can;i<n;i++){ if(p[i].first <= begin){ latest=max(latest,p[i].second); } else{ can=i; break; } } if(latest < begin) return -1;//說(shuō)明沒(méi)有一個(gè)至少在latest+1時(shí)間工作的牛,那么這肯定是錯(cuò)誤的 else return solve(can,latest,num+1);}int main(){ scanf("%d%d",&n,&len); for(int i=0;i<n;i++){ int b,e; scanf("%d%d",&b,&e); p[i]= make_pair(b,e); } sort(p,p+n,cmp); int sum=solve(0,0,0); cout << sum << endl; return 0;}
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 隆尧县| 南乐县| 斗六市| 雷波县| 温州市| 黄石市| 顺义区| 沁阳市| 招远市| 临沂市| 通城县| 石棉县| 松潘县| 隆子县| 饶平县| 中江县| 嵊泗县| 临夏县| 沙洋县| 新竹市| 辽阳县| 瑞丽市| 静乐县| 咸阳市| 扎赉特旗| 遂溪县| 西和县| 疏勒县| 繁峙县| 清河县| 澄城县| 巨野县| 南平市| 仪征市| 西安市| 鞍山市| 翁源县| 皮山县| 交口县| 望城县| 景德镇市|