• CodeForces 1209 B. Jury Size 树状数组处理区间统计问题


    B. Jury Size
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    input.txt
    output
    output.txt

    In 2013, the writers of Berland State University should prepare problems for n Olympiads. We will assume that the Olympiads are numbered with consecutive integers from 1 to n. For each Olympiad we know how many members of the jury must be involved in its preparation, as well as the time required to prepare the problems for her. Namely, the Olympiad number i should be prepared by pipeople for ti days, the preparation for the Olympiad should be a continuous period of time and end exactly one day before the Olympiad. On the day of the Olympiad the juries who have prepared it, already do not work on it.

    For example, if the Olympiad is held on December 9th and the preparation takes 7 people and 6 days, all seven members of the jury will work on the problems of the Olympiad from December, 3rd to December, 8th (the jury members won't be working on the problems of this Olympiad on December 9th, that is, some of them can start preparing problems for some other Olympiad). And if the Olympiad is held on November 3rd and requires 5 days of training, the members of the jury will work from October 29th to November 2nd.

    In order not to overload the jury the following rule was introduced: one member of the jury can not work on the same day on the tasks for different Olympiads. Write a program that determines what the minimum number of people must be part of the jury so that all Olympiads could be prepared in time.

    Input

    The first line contains integer n — the number of Olympiads in 2013 (1 ≤ n ≤ 100). Each of the following n lines contains four integersmidipi and ti — the month and day of the Olympiad (given without leading zeroes), the needed number of the jury members and the time needed to prepare the i-th Olympiad (1 ≤ mi ≤ 12di ≥ 11 ≤ pi, ti ≤ 100), di doesn't exceed the number of days in month mi. The Olympiads are given in the arbitrary order. Several Olympiads can take place in one day.

    Use the modern (Gregorian) calendar in the solution. Note that all dates are given in the year 2013. This is not a leap year, so February has 28 days. Please note, the preparation of some Olympiad can start in 2012 year.

    Output

    Print a single number — the minimum jury size.

    Sample test(s)
    input
    2
    5 23 1 2
    3 13 2 3
    output
    2
    input
    3
    12 9 2 1
    12 8 1 3
    12 8 2 2
    output
    3
    input
    1
    1 10 1 13
    output
    1

    解题思路: 将年月日统一转换成整数,然后成为一个区间(s,t), n个区间(s,t), 将其按照开始时间排序后,利用树状数组统计需要的裁判数量就可以了。
    View Code
     1 #include<stdio.h>
     2 #include<string.h>
     3 #include<iostream>
     4 #include<algorithm>
     5 #include<math.h>
     6 using namespace std;
     7 
     8 const int N = 1000;
     9 
    10 int day[13] = {31,28,31,30,31,30,31,31,30,31,30,31};
    11 int SumDay[13], C[N+10];
    12 int n;
    13 struct node{
    14     int m, d, p, t;
    15     int val;    
    16     void read(){
    17         scanf("%d%d%d%d",&m,&d,&p,&t);
    18         val = 200 + SumDay[m]+d - t;
    19     }
    20     bool operator < (node tmp) const
    21     {
    22         return val < tmp.val;    
    23     }
    24 }mod[110];
    25 void init(){
    26     SumDay[1] = 0;
    27     for(int i = 2; i <= 12; i++)
    28         SumDay[i] = SumDay[i-1]+day[i];
    29 }
    30 void update( int x, int val)
    31 {
    32     for( ; x < N; x += x&(-x) )
    33         C[x] += val;
    34 }
    35 int read( int x )
    36 {
    37     int res = 0;
    38     for( ; x >= 1; x -= x&(-x) )
    39         res += C[x];
    40     return res;
    41 }
    42 int main()
    43 {
    44     freopen( "input.txt" , "r", stdin);
    45     freopen( "output.txt", "w", stdout);
    46     init();    
    47     while( scanf("%d",&n) != EOF)
    48     {
    49             for(int i = 0; i < n; i++)
    50                 mod[i].read();
    51             sort( mod, mod+n );
    52             memset( C, 0, sizeof(C));    
    53             int cur = 0;    
    54             for(int i = 0; i < n; i++)
    55             {
    56                 int freejury = cur-read( mod[i].val );    
    57                 int needjury = freejury-mod[i].p;    
    58                 if( needjury < 0 )    cur -= needjury;    
    59                 update( mod[i].val, mod[i].p );
    60                 update( mod[i].val+mod[i].t, -mod[i].p );
    61             }    
    62             printf("%d\n", cur );    
    63     }
    64     return 0;
    65 }
  • 相关阅读:
    APP自动化中三大定位工具
    解决引入矢量图标库报错Refused to load the stylesheet 'XXX' because it violates the following Content Security Policy directive: "defaultsrc 'self'". Note that 'stylesrcelem' 问题
    解决本地好用,打包后JSON中文乱码问题
    关于Fiddler使用过程中突然不能抓包的问题
    【MySQL】mysqldump从所有数据库备份中还原某个指定的库
    【MongoDB】Prometheus监控MongoDB
    【MySQL】MySQL8确认哪些参数在使用以及来源
    【PostgreSQL】PostgreSQL 15移除了Stats Collector
    【MySQL】Authentication plugin 'caching_sha2_password' reported error
    【MySQL】MariaDB使用connect存储引擎访问SQLServer中的表
  • 原文地址:https://www.cnblogs.com/yefeng1627/p/2810366.html
Copyright © 2020-2023  润新知