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 ...
随机推荐
- HAL库PWM
1.占空比控制 a.在CUBMX的TIM下选择时钟源,选择通道为模式PWM Generation ch1 ,设置分频系数,初始值,不需要自动重装载,选择PWM模式1或2,设置比较值pulse,设置初始 ...
- xilinx DMA IP核(一) —— loop测试 代码注释
本篇笔记中的代码来自:米联科技的教程“第三季第一篇的DMA_LOOP环路测试” 硬件的连接如下图所示: 图:DMA Loop Block Design 橘色的线就是DMA加FIFO组成的一个LOOP循 ...
- servlet的url-pattern规则
https://www.cnblogs.com/canger/p/6084846.html
- MongoDB与c#(二)简单例子 使用1.7版本驱动
//创建数据库链接 在1.7的版本驱动中这样写是会报 MongoServer方法已过时的 //MongoServer server = MongoDB.Driver.Mongo ...
- Android的网络编程
1.3主要接口 Android平台有三种网络接口可以使用,他们分别是:java.net.*(标准Java接口).Org.apache接口和Android.net.*(Android网络接口).下面分别 ...
- MySQL数据库-错误1166 - Incorrect column name 'xxx' 的解决方法
在用Navicat for MySQL给MySQL数据库修改表的字段时报如下的错误: 解决方法:检查字段里面是不是有空格,去掉就可以了.
- NetXray
NetXRay是由Cinco Networks公司开发的一个用于高级分组检错的软件,功能很强大.IP地址查询工具. 硬件要求 对硬件要求低,可运行常用的windows平台. 主要功能 1.监视网络状态 ...
- IOS多选单选相册图片
之前做项目让实现多选相册的图片,自己写了一个demo一直保存在电脑上,今天下午发现电脑128G的容量已经快没有了,准备清理电脑,所以把之前做的一些demo放在博客上,以后方便用. 1.首先准备3个图片 ...
- Python——爬虫学习1
爬虫了解一下 网络爬虫(Web crawler),是一种按照一定的规则,自动地抓取万维网信息的程序或者脚本. Python的安装 本篇教程采用Python3 来写,所以你需要给你的电脑装上Python ...
- php中的字符串常用函数(二) substr() 截取字符串
//substr($str, startIndex, length) //截取方向都是从左向右的. //length不写默认截取到最后一个. //length为正是个数(包括开头的个数),为负是索引( ...