Codeforces Round #419 (Div. 2)(A+B)

来源:互联网 发布:ae cs6 mac汉化破解版 编辑:程序博客网 时间:2024/05/17 08:52

A. Karen and Morning
time limit per test2 seconds
memory limit per test512 megabytes
inputstandard input
outputstandard 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, because 05: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.
题意:一个人从hh:mm开始睡觉,睡到一个回文串时间醒,问最短时间。
题解:暴力很好写,但是当时抽风了不想写。于是写了一个比暴力还SB的暴暴力。
代码:

#include<bits/stdc++.h>#define ll long longusing namespace std;int h[100]={0,1,2,3,4,5,10,11,12,13,14,15,20,21,22,23};int m[100]={0,10,20,30,40,50,1,11,21,31,41,51,02,12,22,32};int main(){    int H,M;    scanf("%d:%d",&H,&M);        for(int i=0;i<16;i++)        {            if(h[i]>=H)            {                if(M<=m[i])                {                    cout<<(h[i]-H)*60+m[i]-M<<endl;                    return 0;                }                else                {                    if(i==15)                    {                        cout<<60-M<<endl;                        return 0;                    }                    else                    {                        if(h[i]==H)                        cout<<(h[i+1]-H)*60-(M-m[i+1])<<endl;                        else                        cout<<(h[i]-H)*60-(M-m[i])<<endl;                        return 0;                    }                }            }        }}

B. Karen and Coffee
time limit per test2.5 seconds
memory limit per test512 megabytes
inputstandard input
outputstandard 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, n, k (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.

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.

题意:
n个操作,q次询问,问区间内>==k数的个数,操作为l,r内+1.
题解:
扫面线扫过去就行。
代码:

#include<bits/stdc++.h>#define ll long longusing namespace std;int s[250000];int a[2500000];int output[250000];int n,k,q,l,r,now;int sz=200000;int main(){    int n,k,q;    cin>>n>>k>>q;        for(int i=1;i<=n;i++)        {           cin>>l>>r;            s[l]++;            s[r+1]--;        }         now=0;        for(int i=0;i<=sz;i++)        {            now+=s[i];            a[i]=now;            if(a[i]>=k)a[i]=1;            else a[i]=0;        }        for(int i=1;i<=sz;i++)        {            output[i]=output[i-1]+a[i];        }        while(q--)        {            cin>>l>>r;            cout<<output[r]-output[l-1]<<endl;        }}
原创粉丝点击