Codeforces Round #419 (Div. 2)
Codeforces Round #419 (Div. 2)
http://codeforces.com/contest/816/problem/A
Karen is getting ready for a new school day!
![](http://codeforces.com/predownloaded/10/10/101006b28ff0912f16c1d39e67206ca4b0b6da23.png)
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.
The first and only line of input contains a single string in the format hh:mm (00 ≤ hh ≤ 23, 00 ≤ mm ≤ 59).
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.
05:39
11
13:31
0
23:59
1
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.
题意:给你一个时间,问你至少再过多长时间,才能变成一个回文数。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
/*
模拟时间
*/
#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);
}
http://codeforces.com/contest/816/problem/B
To stay woke and attentive during classes, Karen needs some coffee!
![](http://codeforces.com/predownloaded/02/15/02159e70847762eaf87fdca280025a766c8a564b.png)
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?
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.
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
3
3
0
4
2 1 1
1 1
200000 200000
90 100
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 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.
- 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个温度区间,k,Q个询问,每个询问给出一个温度区间x--y。问这之间有多少个温度在给出K的温度区间内。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
/*
差分即可
*/
#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;
}
http://codeforces.com/contest/816/problem/C