Codeforces Round #419 A+B
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.
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
Note
In the first test case, the minimum number of minutes Karen should sleep for is . She can wake up at :, when the time is a palindrome. In the second test case, Karen can wake up immediately, as the current time, :, is already a palindrome. In the third test case, the minimum number of minutes Karen should sleep for is minute. She can wake up at :, when the time is a palindrome.
Note:
题目大意:
输入一个时间,判断多少时间之后能够组成一个回文串
解题思路:
按照时间的运算法则,一分钟一分钟的增加,每增加一分钟就判断一次,直到组成回文时间
AC代码:
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
using namespace std; int main()
{
int h,m;
while (~scanf("%d:%d",&h,&m))
{
int sum = ;
while (h/ != m% || h% != m/){
m ++;
if (m == )
{
m = ; h ++;
}
if (h == )
h = ;
sum ++;
}
printf("%d\n",sum);
}
return ;
}
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?
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 recipes. The first one recommends brewing the coffee between and degrees, inclusive.
The second one recommends brewing the coffee between and degrees, inclusive.
The third one recommends brewing the coffee between and degrees, inclusive.
A temperature is admissible if at least recipes recommend it. She asks questions. In her first question, she wants to know the number of admissible integer temperatures between and degrees, inclusive. There are : , and degrees are all admissible. In her second question, she wants to know the number of admissible integer temperatures between and degrees, inclusive. There are : , and degrees are all admissible. In her third question, she wants to know the number of admissible integer temperatures between and degrees, inclusive. There are none. In her final question, she wants to know the number of admissible integer temperatures between and degrees, inclusive. There are : , , and degrees are all admissible. In the second test case, Karen knows recipes. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 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 degrees.
A temperature is admissible if at least 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代码:
#include <stdio.h>
#include <string.h> int s[];
int main ()
{
int n,k,i,q,x,y;
while (~scanf("%d%d%d",&n,&k,&q))
{
for (i = ; i < n; i ++)
{
scanf("%d%d",&x,&y);
s[x] ++; s[y+] --;
} for (i = ; i < ; i ++)
s[i] += s[i-]; // 将所有覆盖的位置的区间个数 打表
for (i = ; i < ; i ++)
s[i] = (s[i]>=k); // 大于k个的标记为1 否则为0
for (i = ; i < ; i ++)
s[i] += s[i-]; // 计算出前缀数组和
while (q --)
{
scanf("%d%d",&x,&y);
printf("%d\n",s[y]-s[x-]);
}
}
return ;
}
Codeforces Round #419 A+B的更多相关文章
- Codeforces Round #419 D. Karen and Test
Karen has just arrived at school, and she has a math test today! The test is about basic addition an ...
- Codeforces Round #419 (Div. 2) E. Karen and Supermarket(树形dp)
http://codeforces.com/contest/816/problem/E 题意: 去超市买东西,共有m块钱,每件商品有优惠卷可用,前提是xi商品的优惠券被用.问最多能买多少件商品? 思路 ...
- Codeforces Round #419 (Div. 2) B. Karen and Coffee(经典前缀和)
http://codeforces.com/contest/816/problem/B To stay woke and attentive during classes, Karen needs s ...
- Codeforces Round #419 (Div. 2) A. Karen and Morning(模拟)
http://codeforces.com/contest/816/problem/A 题意: 给出一个时间,问最少过多少时间后是回文串. 思路: 模拟,先把小时的逆串计算出来: ① 如果逆串=分钟, ...
- Codeforces Round #419 (Div. 2)
1.题目A:Karen and Morning 题意: 给出hh:mm格式的时间,问至少经过多少分钟后,该时刻为回文字符串? 思路: 简单模拟,从当前时刻开始,如果hh的回文rh等于mm则停止累计.否 ...
- codeforces round #419 E. Karen and Supermarket
On the way home, Karen decided to stop by the supermarket to buy some groceries. She needs to buy a ...
- codeforces round #419 C. Karen and Game
C. Karen and Game time limit per test 2 seconds memory limit per test 512 megabytes input standard i ...
- codeforces round #419 B. Karen and Coffee
To stay woke and attentive during classes, Karen needs some coffee! Karen, a coffee aficionado, want ...
- codeforces round #419 A. Karen and Morning
Karen is getting ready for a new school day! It is currently hh:mm, given in a 24-hour format. As yo ...
- Codeforces Round #419 Div. 1
A:暴力枚举第一列加多少次,显然这样能确定一种方案. #include<iostream> #include<cstdio> #include<cmath> #in ...
随机推荐
- 【算法笔记】A1054 The Dominant Color
1054 The Dominant Color (20 分) Behind the scenes in the computer's memory, color is always talked ...
- HDU4641 || 6194多校 (后缀自动机-最少出现K次的字串个数 || 恰好出现K次字符串的个数)
http://acm.hdu.edu.cn/showproblem.php?pid=4641 http://acm.hdu.edu.cn/showproblem.php?pid=6194 题意: 开始 ...
- Gradle学习系列(二)
AS的逐渐成熟和完善,已有越来越多的项目开发都开始转向AS了,必然的对Gradel的认识和使用是很有必要了.我们已经知道 Gradle 是用来架构 Java项目了,对于Android Project来 ...
- (转)如何在CentOS / RHEL 7上安装Elasticsearch,Logstash和Kibana(ELK)
原文:https://www.howtoing.com/install-elasticsearch-logstash-and-kibana-elk-stack-on-centos-rhel-7 如果你 ...
- Fetch使用方法
前言: fetch是用来取代传统的XMLHttpRequest的. 它的优点很多,包括链式调用的语法.返回promise等. 什么是fetch? fetch api是基于promise的设计,它是为了 ...
- JDBC处理Transaction
package com.ayang.jdbc; import java.sql.*; /** * transaction的构成,随便写一句insenrt,一执行executeUpdate(),它自动提 ...
- hibernate3.3.2搭建log4j日志环境
日志的框架有很多,hibernate3.3.2用的是slf4j,slf4j简单理解为一个接口,标准.具体的实现可以是不同的实现(如slf4j自己的实现,log4j等).slf就像JDBC,JPA.自己 ...
- Fix the error in NeighboringCellInfo.java in CM10.1
1.error messenge: frameworks/base/telephony/java/android/telephony/NeighboringCellInfo.java:: error ...
- springboot-21-maven多环境打包
前几天项目需要用到分环境打包, 于是研究了下, 由于项目基于springboot的, 所以分两个情况进行说明: 1), springboot的多环境配置 2), maven-springboot的多环 ...
- FocusBI: 微软商业智能教程目录介绍(原创)
关注微信公众号:FocusBI 查看更多文章:加QQ群:808774277 获取学习资料和一起探讨问题. <商业智能教程>pdf下载地址 链接:https://pan.baidu.com/ ...