zoukankan      html  css  js  c++  java
  • 【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
  • 相关阅读:
    学习的过程必须要知其所以然
    根据人类的学习与记忆过程来高效学习
    大脑的信息获取特点与记忆模式
    31个让你变聪明的有效方法
    心智模式:心智模式的更多资料
    心智模式:仁者见仁、智者见智
    心智模式:如何看待成败?
    心智模式:如何面对逆境?
    心智模式:认识你自己
    阿里巴巴JAVA工程师面试经验
  • 原文地址:https://www.cnblogs.com/ismdeep/p/2624392.html
Copyright © 2011-2022 走看看