【ECJTU_ACM 11级队员2012年暑假训练赛(7) - A - Happy Telephones】
Description
In the land of Eden, all phone conversations are happy ones. People complaining on the phone are immediately put in jail. To enforce this law, the police taps all phone conversations.
The police wants to hire the appopiate number of operators to listen to all conversations in a given period of time. Unfortunately, each of their operators can listen to one conversation only before needing a really long break to rest from the effort.
As a contractor of the police department, you have been asked to provide a program capable of determining the required number of operators. If the program does not work correctly, you will be put in jail as well, along with all the unhappy complainers. Do you really want to end up there?
Input
Afterwards follow M lines containing the time intervals the police are interested in, each described by two integers Start andDuration, in the same format and with the same meaning and constraints as those in the telephone calls. The last test case is represented by N = M = 0 and must not be processed.
Output
Sample Input
3 2 3 4 2 5 1 2 0 10 6 5 5 8 0 6 8 2 1 2 8 9 0 10 9 1 10 1 0 0
Sample Output
3 2 1 0
1 #include <iostream> 2 #include <stdio.h> 3 using namespace std; 4 struct Phone 5 { 6 int iSource; 7 int iDestination; 8 int iStart; 9 int iDuring; 10 }; 11 12 Phone iPhone[10001]; 13 14 int main() 15 { 16 //freopen("in.dat", "r", stdin); 17 int n, m; 18 while (scanf("%d%d", &n, &m) != EOF && n + m) 19 { 20 for (int i = 0; i < n; i++) 21 { 22 scanf("%d%d%d%d", &iPhone[i].iSource, &iPhone[i].iDestination, &iPhone[i].iStart, &iPhone[i].iDuring); 23 } 24 25 for (int i = 0; i < m; i++) 26 { 27 int iStart, iDuring; 28 int iSum = 0; 29 scanf("%d%d", &iStart, &iDuring); 30 for (int j = 0; j < n; j++) 31 { 32 if (iPhone[j].iStart < iStart && iPhone[j].iStart + iPhone[j].iDuring > iStart) 33 { 34 iSum++; 35 } 36 if (iPhone[j].iStart == iStart) 37 { 38 iSum++; 39 } 40 if (iPhone[j].iStart > iStart && iStart + iDuring > iPhone[j].iStart) 41 { 42 iSum++; 43 } 44 } 45 printf("%d\n", iSum); 46 } 47 } 48 return 0; 49 } 50 51 52 // end 53 // iCoding@CodeLab