POJ2376 Cleaning Shifts

Source: Internet
Author: User

Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 18217 Accepted: 4636

Description

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

Each cow is a available at some interval of times during the day for work on cleaning. Any cow that's selected for cleaning duty would work for the entirety of her interval.

Your job is-to-help Farmer John Assign some cows-shifts so (i) every shift have at least one cow assigned to it, an D (ii) as few cows as possible is 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 isn't possible to assign a cow to each shift.

Sample Input

3 101 73) 66 10

Sample Output

2

Hint

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

INPUT DETAILS:

There is 3 cows and 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 is covered. There is no-to-cover all the shifts using fewer than 2 cows.

Source

Usaco 2004 December Silver has n small intervals and a large interval from 1 to T. Give the start and end point of n small interval, ask at least a few can cover large interval, if no solution output-1 by the cell between the left endpoint from small to large sort, each greedy choice on the line. Note: As long as each integer points are overwritten, for example, 1 2,3 4,5 10 These three intervals can be covered 1-10 discuss in the various data are over, I do not know why is Wawawa. Finally replaced by another kind of unordered, each time from the left endpoint has been overwritten (or the left end point next to the covered points) to find the furthest right end of the coverage of the wording, AC

1 /*by Silvern*/2#include <iostream>3#include <cstdio>4#include <cmath>5#include <cstring>6#include <algorithm>7 using namespacestd;8 Const intmxn=1000200;9 intn,t;Ten intmx[mxn];//starting point is mx[], farthest right end position One intans=0; A intMain () { -scanf"%d%d",&n,&t); -     intb; the     inti,j; -      for(i=1; i<=n;i++){ -scanf"%d%d",&a,&b); -mx[a]=Max (mx[a],b); +     } -     intlast=1, now=1; +     intEd; A      while(now<=t) {//now is the length that is currently covered atEd=0; -          for(i=last;i<=now;i++){ -             if(mx[i]>ed) { -ed=mx[i];last=i; -             } -         } in         if(ed+1==Now ) { -printf"-1\n"); to             return 0; +         } -Now=ed+1; ans++; the         if(ed>=t) Break; *     } $     if(ed>=t) printf ("%d\n", ans);Panax Notoginseng     Elseprintf"-1\n"); -     return 0; the } + /* A const int mxn=26000; the struct line{ + int l,r; - }A[MXN]; $ int cmp (const line A,const line B) { $ if (A.L!=B.L) return a.l<b.l; - return a.r<b.r; - } the int st,ed; - int n,t;Wuyi int main () { the int i,j; - scanf ("%d%d", &n,&t); Wu For (i=1;i<=n;i++) - scanf ("%d%d", &A[I].L,&A[I].R); About sort (a+1,a+n+1,cmp); $ ed=0; - int ans=0; - if (a[1].l<=1) - For (i=1;i<=n;i++) { A int nxt=0; + While (i+1<=n && a[i+1].l<=ed+1) { the i++; - Nxt=max (NXT,A[I].R); $         } the if (a[i].l<=ed+1) Nxt=max (NXT,A[I].R); the if (nxt>ed) { the ed=nxt; the ans++; -         } in if (ed>=t) break; the     } the if (ed>=t) printf ("%d\n", ans); About Else printf (" -1\n"); the return 0; the }*/

POJ2376 Cleaning Shifts

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.