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 ...
随机推荐
- MySQL的库、表详细操作
本节目录 一.库操作 二.表操作 三.行操作 一.库操作 1.创建数据库 1.1 语法 CREATE DATABASE 数据库名 charset utf8; 1.2 数据库命名规则 可以由字母.数字. ...
- python3随机生成中文字符
运行环境在Python3.6下,Python2的解决方案网上有很多. ---2017.10.18 第一种方法:Unicode码 在unicode码中,汉字的范围是(0x4E00, 9FBF) impo ...
- 在Ubuntu16.04集群上手工部署Kubernetes
目前Kubernetes为Ubuntu提供的kube-up脚本,不支持15.10以及16.04这两个使用systemd作为init系统的版本. 这里详细介绍一下如何以非Docker方式在Ubuntu1 ...
- 【树】Validate Binary Search Tree
需要注意的是,左子树的所有节点都要比根节点小,而非只是其左孩子比其小,右子树同样.这是很容易出错的一点是,很多人往往只考虑了每个根节点比其左孩子大比其右孩子小.如下面非二分查找树,如果只比较节点和其左 ...
- Cloudera Manager安装之利用parcels方式(在线或离线)安装3或4节点集群(包含最新稳定版本或指定版本的安装)(添加服务)(Ubuntu14.04)(五)
前期博客 Cloudera Manager安装之Cloudera Manager 5.6.X安装(tar方式.rpm方式和yum方式) (Ubuntu14.04) (三) 如果大家,在启动的时候,比如 ...
- 深入分析java web技术内幕目录一览
Web请求过程 如何发起请求:browser,httpclient http解析:chrome ,cache Dns域名解析:域名缓存 cdn:负载,动态加速,回源 Java I/O I/0类库的基本 ...
- java的instanceof简单使用
instanceof:是java中用来判断一个对象属于哪个类型的关键字 (instanceof是instance和of两个单词组成,但of并没有大写) eg: public class Test{ ...
- 关于docker的理解随记
1.容器其实不是什么新技术,说白了就是namespace对资源进行隔离,再加UFS实现分层镜像,以及cgroup实现资源限制.这些技术,都是linux中已有的技术,而且有些技术很早之前就有了. 2.上 ...
- CPU漏洞补丁修复导致KeServiceDescriptorTable获取变更
一.前言 2018年元旦,出现的cpu的漏洞,可以在windows环三直接读取内核数据,windows对该漏洞提供补丁,补丁增加了一个页表,对应的内核处理也增加了,接下来我们看下补丁修复的表象以及对K ...
- 创建.NET Core程序的Nuget Package
最近在看ASP.NET Core MVC的教材,几乎每章开始都要重复从Empty project开始创建一个ASP.NET Core的项目,然后手动修改project.json,增加经典三目录(Mod ...