zoukankan      html  css  js  c++  java
  • Codeforces Round #419 A+B

    time limit per test  2 seconds
    memory limit per test  512 megabytes
     

    Karen is getting ready for a new school day!

    It is currently hh:mm, given in a 24-hour format. As you know, Karen loves palindromes, and she believes that it is good luck to wake up when the time is a palindrome.

    What is the minimum number of minutes she should sleep, such that, when she wakes up, the time is a palindrome?

    Remember that a palindrome is a string that reads the same forwards and backwards. For instance, 05:39 is not a palindrome, because05:39 backwards is 93:50. On the other hand, 05:50 is a palindrome, because 05:50 backwards is 05:50.

    Input

    The first and only line of input contains a single string in the format hh:mm (00 ≤  hh  ≤ 23, 00 ≤  mm  ≤ 59).

    Output

    Output a single integer on a line by itself, the minimum number of minutes she should sleep, such that, when she wakes up, the time is a palindrome.

     
    input
    05:39
    output
    11
    input
    13:31
    output
    0
    input
    23:59
    output
    1

    Note
    In the first test case, the minimum number of minutes Karen should sleep for is 11. She can wake up at 05:50, when the time is a palindrome.
    
    In the second test case, Karen can wake up immediately, as the current time, 13:31, is already a palindrome.
    
    In the third test case, the minimum number of minutes Karen should sleep for is 1 minute. She can wake up at 00:00, when the time is a palindrome.
    Note:

    题目大意:

        输入一个时间,判断多少时间之后能够组成一个回文串

    解题思路:

        按照时间的运算法则,一分钟一分钟的增加,每增加一分钟就判断一次,直到组成回文时间 

    AC代码:

     1 #include <stdio.h>
     2 #include <string.h>
     3 #include <math.h>
     4 #include <algorithm>
     5 using namespace std;
     6 
     7 int main()
     8 {
     9     int h,m;
    10     while (~scanf("%d:%d",&h,&m))
    11     {
    12         int sum = 0;
    13         while (h/10 != m%10 || h%10 != m/10){
    14             m ++;
    15             if (m == 60)
    16             {
    17                 m = 0; h ++;
    18             }
    19             if (h == 24)
    20                 h = 0;
    21             sum ++;
    22         }
    23         printf("%d
    ",sum);
    24     }
    25     return 0;
    26 }
    time limit per test  2.5 seconds
    memory limit per test  512 megabytes
     

    To stay woke and attentive during classes, Karen needs some coffee!

    Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".

    She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between li and ri degrees, inclusive, to achieve the optimal taste.

    Karen thinks that a temperature is admissible if at least k recipes recommend it.

    Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?

    Input

    The first line of input contains three integers, nk (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.

    The next n lines describe the recipes. Specifically, the i-th line among these contains two integers li and ri (1 ≤ li ≤ ri ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between li and ri degrees, inclusive.

    The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.

    Output

    For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.

     
    input
    3 2 4
    91 94
    92 97
    97 99
    92 94
    93 97
    95 96
    90 100
    output
    3
    3
    0
    4
    input
    2 1 1
    1 1
    200000 200000
    90 100
    output
    0

    In the first test case, Karen knows 3 recipes.
    
    The first one recommends brewing the coffee between 91 and 94 degrees, inclusive.
    The second one recommends brewing the coffee between 92 and 97 degrees, inclusive.
    The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
    A temperature is admissible if at least 2 recipes recommend it.
    
    She asks 4 questions.
    
    In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
    
    In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
    
    In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
    
    In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
    
    In the second test case, Karen knows 2 recipes.
    
    The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree.
    The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
    A temperature is admissible if at least 1 recipe recommends it.
    
    In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none.
    Note:



    题目大意:
          给出n个配料区间,q个查询区间,问每次查询时,该查询区间内有多少个点至少被k个配料区间覆盖。

    解题思路:
         预处理+前缀数组 一共三个数组
    .第一个循环后S[i]表示i点被覆盖的次数,第二个循环S[i] 表示i点是否满足条件 ,第三个循环S[i]计算前缀数组和

    AC代码:
     1 #include <stdio.h>
     2 #include <string.h>
     3 
     4 int s[2000100];
     5 int main ()
     6 {
     7     int n,k,i,q,x,y;
     8     while (~scanf("%d%d%d",&n,&k,&q))
     9     {
    10         for (i = 0; i < n; i ++)
    11         {
    12             scanf("%d%d",&x,&y);
    13             s[x] ++; s[y+1] --;    
    14         }
    15         
    16         for (i = 1; i < 200010; i ++)
    17             s[i] += s[i-1];    // 将所有覆盖的位置的区间个数 打表 
    18         for (i = 1; i < 200010; i ++)
    19             s[i] = (s[i]>=k);   // 大于k个的标记为1 否则为0 
    20         for (i = 1; i < 200010; i ++)
    21             s[i] += s[i-1];     // 计算出前缀数组和 
    22         while (q --)
    23         {
    24             scanf("%d%d",&x,&y);
    25             printf("%d
    ",s[y]-s[x-1]);
    26         }
    27     }
    28     return 0;
    29 }
    
    
    
     
  • 相关阅读:
    hihoCoder 1092 : Have Lunch Together
    UVa 11401 三角形的个数
    2020杭电多校第一场 hdu6756 Finding a MEX
    2020杭电多校第二场 hdu6774 String Distance
    2020杭电多校第一场 hdu6759 Leading Robots
    2020牛客暑期多校训练营(第二场)A、B、C、D、F、G、H、J
    2020牛客暑期多校训练营(第二场)All with Pairs
    2020牛客暑期多校训练营(第二场)Boundary
    2020牛客暑期多校训练营(第二场)Just Shuffle
    2020牛客暑期多校训练营(第二场)Happy Triangle
  • 原文地址:https://www.cnblogs.com/yoke/p/7043631.html
Copyright © 2011-2022 走看看