博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #419 A+B
阅读量:5062 次
发布时间:2019-06-12

本文共 6484 字,大约阅读时间需要 21 分钟。

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
NoteIn 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 
2 #include
3 #include
4 #include
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\n",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 
2 #include
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\n",s[y]-s[x-1]);26 }27 }28 return 0;29 }
 

 

 

转载于:https://www.cnblogs.com/yoke/p/7043631.html

你可能感兴趣的文章
手动从Spring中获取指定对象
查看>>
中缀表达式转后缀表达式,以及计算结果.
查看>>
Oracle的安装与卸载
查看>>
(转载)CentOS: 开放80、22、3306端口操作
查看>>
[HDU] 1074 Doing Homework (NP性质的DP,远没有过去的自己写得好了)
查看>>
ActiveMQ
查看>>
java 数组排序并去重
查看>>
JAVA_OA管理系统(四)番外篇:使用Spring注解注入属性
查看>>
task1-9
查看>>
【收藏】Web App 被看衰,Hybrid App 才是新王道
查看>>
九度oj 题目1064:反序数
查看>>
DS博客大作业--树
查看>>
ElasticSearch 6.0 源码编译
查看>>
uva10870 矩阵
查看>>
小白javascript(一):作用域
查看>>
滚动条CSS样式控制浏览器滚动条颜色的代码
查看>>
差距在哪里-上进人必看
查看>>
2013长春网赛 1006 hdu 4764 Stone(巴什博弈)
查看>>
查询指定表的所有列
查看>>
一篇文章让你明白python的装饰器
查看>>