/*
Select non-intersecting intervals
Time limit: Ms | Memory Limit: 65535 KB
Difficulty: 2
Describe
All right. The aim of this problem is to let you know the three classical problems of greedy problem: interval selection problem, interval coverage problem, and the problem of choosing disjoint interval. There are a lot of greedy problems that can be translated into these three types of problems.
Well, for that matter. is to give a series of intervals, the most interval, requires the most interval number, these intervals do not intersect, it is important to note that these intervals are closed intervals.
Just for Fun
Input
First row one number n is the number of intervals (n<=1000)
Next there are n rows, each with two number, a, or two endpoints for the interval, and a, b in the int range.
EOF ends.
Output
Output as shown in the sample
Sample input
2
1 10
10 11
3
1 10
10 11
11 20
Sample output
Case 1:
1.
Case 2:
2.
Long time no algorithm, find some water problem practice practiced hand, small greedy.
There's a deceptive place to a<b. Swap the location of the input data.
*/
#include <stdio.h> #include <stdlib.h> struct node {int s; Start int t;
END};
Node a[1001];
int cmp (const void *a,const void *b) {node *c = (node *) A;
Node *d = (node *) b;
if (c->t>d->t) {return 1;
} else {return-1;
}} int main () {int n,i,ans,tmp;
int num = 0;
while (scanf ("%d", &n)!=eof) {if (n==0) {printf ("0\n"); } else {for (i=0;i<n;i++) {scanf ("%d%d", &a[i].s,&a[i].
T);
if (a[i].s>a[i].t)//Pit a<b, swap the location of the input data.
{int tem = A[I].S;
A[I].S = a[i].t;
a[i].t = tem;
}} qsort (A,n,sizeof (a[0]), CMP);//From small to large sort tmp=0;
Ans=1; for (i=1;i<n;i++) {if (a[i].s>a[tmp].t)//Take a second start and the first end comparison Greater than start plus, and place the position down {ans++;
Tmp=i;
}} printf ("Case%d:\n", ++num);
printf ("%d.\n", ans);
}} return 0; }