zoukankan      html  css  js  c++  java
  • Codeforces Round #419 (Div. 2)

    Codeforces Round #419 (Div. 2) 

     

    http://codeforces.com/contest/816/problem/A

    A. Karen and Morning
    time limit per test
    2 seconds
    memory limit per test
    512 megabytes
    input
    standard input
    output
    standard output

    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.

    Examples
    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.

     

    题意:给你一个时间,问你至少再过多长时间,才能变成一个回文数。

    /*
    模拟时间 
    */
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    
    using namespace std;
    char s[10];
    
    int main()
    {
        scanf("%s",s);
        int a,b,c,d;
        a=s[0]-'0';b=s[1]-'0';
        c=s[3]-'0';d=s[4]-'0';
        int num=0;
        while(1)
        {
            if(a==d&&b==c)break;
            num++;d++;
            if(d>=10)
            {
                d=0;c++;
                if(c>=6)
                {
                    c=0;b++;
                    if(b>=10) b=0,a++;
                    if(a*10+b>=24) a=0,b=0;
                }
            }
        }
        printf("%d",num);
    }
    View Code

     

    http://codeforces.com/contest/816/problem/B

    B. Karen and Coffee
    time limit per test
    2.5 seconds
    memory limit per test
    512 megabytes
    input
    standard input
    output
    standard output

    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.

    Examples
    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
    Note

    In the first test case, Karen knows 3 recipes.

    1. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive.
    2. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive.
    3. 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 are3: 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.

    1. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree.
    2. 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.

     

    题意:给出n个温度区间,k,Q个询问,每个询问给出一个温度区间x--y。问这之间有多少个温度在给出K的温度区间内。

    /*
    差分即可 
    */ 
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    
    using namespace std;
    const int N = 3e5+10;
    
    int n,k,q,x,y,a[N],b[N];
    
    int main()
    {
        scanf("%d%d%d",&n,&k,&q);
        for(int i = 1; i <= n; ++i)
        {
            scanf("%d%d",&x,&y);
            b[x]++;b[y+1]--;
        }
        for(int i = 1; i <= 200000; ++i)
        {
            b[i]+=b[i-1];
            if(b[i]>=k) a[i]=1;
            else a[i]=0;
        }
        for(int i = 1; i <= 200000; ++i) a[i]+=a[i-1];
        for(int i=1; i<=q; i++)
        {
            int x,y;
            scanf("%d%d",&x,&y);
            cout<<a[y]-a[x-1]<<endl;
        }
        return 0;
    }
    View Code

     

    http://codeforces.com/contest/816/problem/C

    C. Karen and Game
    time limit per test
    2 seconds
    memory limit per test
    512 megabytes
    input
    standard input
    output
    standard output

    On the way to school, Karen became fixated on the puzzle game on her phone!

    The game is played as follows. In each level, you have a grid with n rows and m columns. Each cell originally contains the number 0.

    One move consists of choosing one row or column, and adding 1 to all of the cells in that row or column.

    To win the level, after all the moves, the number in the cell at the i-th row and j-th column should be equal to gi, j.

    Karen is stuck on one level, and wants to know a way to beat this level using the minimum number of moves. Please, help her with this task!

    Input

    The first line of input contains two integers, n and m (1 ≤ n, m ≤ 100), the number of rows and the number of columns in the grid, respectively.

    The next n lines each contain m integers. In particular, the j-th integer in the i-th of these rows contains gi, j (0 ≤ gi, j ≤ 500).

    Output

    If there is an error and it is actually not possible to beat the level, output a single integer -1.

    Otherwise, on the first line, output a single integer k, the minimum number of moves necessary to beat the level.

    The next k lines should each contain one of the following, describing the moves in the order they must be done:

    • row x, (1 ≤ x ≤ n) describing a move of the form "choose the x-th row".
    • col x, (1 ≤ x ≤ m) describing a move of the form "choose the x-th column".

    If there are multiple optimal solutions, output any one of them.

    Examples
    input
    3 5
    2 2 2 3 2
    0 0 0 1 0
    1 1 1 2 1
    output
    4
    row 1
    row 1
    col 4
    row 3
    input
    3 3
    0 0 0
    0 1 0
    0 0 0
    output
    -1
    input
    3 3
    1 1 1
    1 1 1
    1 1 1
    output
    3
    row 1
    row 2
    row 3
    Note

    In the first test case, Karen has a grid with 3 rows and 5 columns. She can perform the following 4 moves to beat the level:

    In the second test case, Karen has a grid with 3 rows and 3 columns. It is clear that it is impossible to beat the level; performing any move will create three 1s on the grid, but it is required to only have one 1 in the center.

    In the third test case, Karen has a grid with 3 rows and 3 columns. She can perform the following 3 moves to beat the level:

    Note that this is not the only solution; another solution, among others, is col 1, col 2, col 3.

     

     题意:给你一个n行m列的二维数组,你可以对任意行或列执行一个删除操作,即使该行或列上所有数字-1,如果能使数组全为0,则输出最小操作数以及步骤,不能则输出-1.

    /*
    显然只跟每行每列最小值有关
    看行列那个多,多的先进行操作,这样更优 
    */
    #include <iostream>
    #include <stdio.h>
    #include <cstring>
    #include <string>
    #include <algorithm>
    
    using namespace std;
    
    const int N = 105;
    int n, m;
    int A[N][N];
    int r[N], c[N];
    int doRow()
    {
        int ans = 0;
        for (int i = 0; i < n; ++i)
        {
            int miv = 1000;
            for (int j = 0; j < m; ++j)
                miv = std::min(miv, A[i][j]);
            r[i]=miv;
            ans += r[i];
            for (int j = 0; j < m; ++j)
                A[i][j] -= r[i];
        }
        return ans;
    }
    int doCol()
    {
        int ans = 0;
        for (int j = 0; j < m; ++j)
        {
            int miv = 1000;
            for (int i = 0; i < n; ++i)
                miv = std::min(miv, A[i][j]);
            ans += (c[j] = miv);
            for (int i = 0; i < n; ++i)
                A[i][j] -= c[j];
        }
        return ans;
    }
    int main()
    {
        scanf("%d%d", &n, &m);
        int s = 0;
        for (int i = 0; i < n; ++i)
            for (int j = 0; j < m; ++j)
            {
                scanf("%d", &A[i][j]);
                s += A[i][j];
            }
        int cc, rr;
        if (n > m)
        {
            cc = doCol();
            rr = doRow();
        }
        else
        {
            rr = doRow();
            cc = doCol();
        }
        if (s != cc * n + rr * m) return puts("-1"), 0;
        printf("%d
    ", cc + rr);
        for (int i = 0; i < n; ++i)
            while (r[i]--) printf("row %d
    ", i + 1);
        for (int j = 0; j < m; ++j)
            while (c[j]--) printf("col %d
    ", j + 1);
        return 0;
    }
    View Code

     

    http://codeforces.com/contest/816/problem/D

    D. Karen and Test
    time limit per test
    2 seconds
    memory limit per test
    512 megabytes
    input
    standard input
    output
    standard output

    Karen has just arrived at school, and she has a math test today!

    The test is about basic addition and subtraction. Unfortunately, the teachers were too busy writing tasks for Codeforces rounds, and had no time to make an actual test. So, they just put one question in the test that is worth all the points.

    There are n integers written on a row. Karen must alternately add and subtract each pair of adjacent integers, and write down the sums or differences on the next row. She must repeat this process on the values on the next row, and so on, until only one integer remains. The first operation should be addition.

    Note that, if she ended the previous row by adding the integers, she should start the next row by subtracting, and vice versa.

    The teachers will simply look at the last integer, and then if it is correct, Karen gets a perfect score, otherwise, she gets a zero for the test.

    Karen has studied well for this test, but she is scared that she might make a mistake somewhere and it will cause her final answer to be wrong. If the process is followed, what number can she expect to be written on the last row?

    Since this number can be quite large, output only the non-negative remainder after dividing it by 109 + 7.

    Input

    The first line of input contains a single integer n (1 ≤ n ≤ 200000), the number of numbers written on the first row.

    The next line contains n integers. Specifically, the i-th one among these is ai (1 ≤ ai ≤ 109), the i-th number on the first row.

    Output

    Output a single integer on a line by itself, the number on the final row after performing the process above.

    Since this number can be quite large, print only the non-negative remainder after dividing it by 109 + 7.

    Examples
    input
    5
    3 6 9 12 15
    output
    36
    input
    4
    3 7 5 2
    output
    1000000006
    Note

    In the first test case, the numbers written on the first row are 3, 6, 9, 12 and 15.

    Karen performs the operations as follows:

    The non-negative remainder after dividing the final number by 109 + 7 is still 36, so this is the correct output.

    In the second test case, the numbers written on the first row are 3, 7, 5 and 2.

    Karen performs the operations as follows:

    The non-negative remainder after dividing the final number by 109 + 7 is 109 + 6, so this is the correct output.

     题意 看样例分析

    折花枝,恨花枝,准拟花开人共卮,开时人去时。 怕相思,已相思,轮到相思没处辞,眉间露一丝。
  • 相关阅读:
    DataTable转换成List
    gitbash如何修改可恶的蓝色字体
    nvm use exit status 1
    搭建CNPM私有库
    Angular2项目,刷新后页面显示404错误的?
    基于webpack模块加载,ts里对系统对象prototype的扩展
    Angular2 primeNG的p-dropdown的选中值未初始化
    移动端开发常见问题
    weinre的使用
    利用百度地图API进行GPS坐标转换成百度地图坐标,创建点,标签,多边形
  • 原文地址:https://www.cnblogs.com/L-Memory/p/7468840.html
Copyright © 2011-2022 走看看