国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 汉中市| 金昌市| 邳州市| 沁阳市| 米林县| 鄂伦春自治旗| 景洪市| 樟树市| 佛坪县| 肃宁县| 阿拉尔市| 邹城市| 博湖县| 绍兴市| 云和县| 黄石市| 玉林市| 青铜峡市| 望城县| 宿迁市| 深泽县| 临武县| 景宁| 滕州市| 黑河市| 迭部县| 卢湾区| 微博| 休宁县| 靖边县| 巩留县| 永丰县| 微山县| 黑山县| 仁寿县| 南昌县| 无为县| 青海省| 兴城市| 玛多县| 应城市|