【ECJTU_ACM 11级队员2012年暑假训练赛(7) - A - Happy Telephones】

A - Happy Telephones
Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

Description

Download as PDF
 

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?

 

\epsfbox{p4512.eps}

 

Input

Each test case starts with two integers denoting the number of phone calls  N (  1$ \le$N < 10 000) and the number of intervals  M (  1$ \le$M< 100). This is followed by  N lines describing the telephone calls, each one consisting of four integers  SourceDestinationStartand  DurationSource and  Destination identify the pair of telephone numbers establishing the connection (  0$ \le$SourceDestination$ \le$10 000 000).  Start and  Duration are the start time and duration of the call in seconds (  1$ \le$Duration$ \le$10 000 and  Start $ \geq$ 0). You can safely assume that the sum of  Start and  Duration fits into a 32-bit signed integer.

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

For each of the  M intervals of each test case, print the number of calls that are active during at least one second of the interval.

 

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

 

转载于:https://www.cnblogs.com/ismdeep/archive/2012/08/05/2624392.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值