African ChildrenTime limit: Ms | Memory limit: 65535 KB Difficulty: 2 Description The children of Africa are very dark. Why is it.
First, they are located in the tropics, the solar radiation is serious.
Second, they don't bathe very often. (Perennial lack of water, how to bathe.) )
Now, in an African tribe, they have only one place to bathe, and the bath time is very short and there is a moment of wood. (This is no way, lack of water ah.) )
Each child has a time period to bathe. And they can be washed together (whether you're a boy or a girl).
Then, what time to bathe, who should come to wash, by whom to decide. That must be their great "bath" God. "Bath" God has a timetable that records the children of the tribe and when they can take a bath. Now, the "bath" God wants to ask you, in a day, he needs to open and close at least how many times the bath faucet. Because, it is very laborious to turn the tap on and off, even if it is done instantaneously.
Enter multiple sets of data
The first line is a 0<n<=100.
Next n rows, one time period per line. H1h1:m1m1-h2h2:m2m2,24 hour system.
Ensure that the time period is within a day. However, there is no guarantee that h1h1:m1m1 precedes h2h2:m2m2. The output title describes how many taps the "bath" God needs to open and close at least. Sample input
1
00:12-12:12
2
00:12-12:12
14:00-12:00
Sample output
1
1
Greedy algorithm
#include <stdio.h> #include <stdlib.h> 03.structnode 04. {05.INTP; 06.INTQ; 07.}S[101]; 08.INTCMP (const void *a, constvoid *b) 09. {10.node *c = (node *) A; 11.node *d = (node *) b; 12.if (c->q>d->q) 13.return1; 14.else 15.return-1; 17.intmain () 18. {19. 20.intn,a,b,c,d; 21.while (scanf ("%d", &n)!=eof) 22. {23.intt1; 24.inti; 25.for (i=0;i<n;i++) 26. {27.scanf ("%d:%d-%d:%d", &a,&b,&c,&d); //convert time to minutes
28.s[i] . p=60*a+b; 29.s[i].q=60*c+d; 30.if (S[I].P>S[I].Q) //Guarantee, H1H1:M1M1 prior to h2h2:m2m2.
31.{32.T1=S[I].P; 33.S[I].P=S[I].Q; 34.S[I].Q=T1; 35.} 36.} 37.qsort (S,n,sizeof (s[0]), CMP); //back from small to large sort
38.intans=1; 39.INTK = 0; 40.for (i = 1; i < n; i++) 41. { 42.if (S[I].P >s[k].q)//current one is greater than the next
43.{ 44.K = i; 45.ans++; 46.} 47. 48.} 49.printf ("%d\n", ans); 50.} 51.return0; .}