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
  • 相关阅读:
    sql in not in 案例用 exists not exists 代替
    根据算法规则进行匹配相似车辆
    随机生成临时车牌号
    无法加载 DLL“ParkCOM.dll”: 找不到指定的模块。 (异常来自 HRESULT:0x8007007E) 终结者
    c# 除掉前三个字符,剩下的4个字符全为数字方为特殊车辆
    UI设计文本框解决Placeholder的在IE10 以下 IE 9 IE8 IE 7 的兼容问题
    EF框架 对字段属性为NULL的空值处理 类型前面加上?保证EF列表读取显示数据不会报异常
    boost::property_tree读取解析.xml文件
    C++ URLencode library
    http与中文编码传输
  • 原文地址:https://www.cnblogs.com/ismdeep/p/2624392.html
Copyright © 2011-2022 走看看