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 ...
随机推荐
- ThreadLocal系列(一)-ThreadLocal的使用及原理解析
ThreadLocal系列之ThreadLocal(源码基于java8) 项目中我们如果想要某个对象在程序运行中的任意位置获取到,就需要借助ThreadLocal来实现,这个对象称作线程的本地变量,下 ...
- linux 命令 htop & 重定向 top, bashrc文件
最近在用linux服务器跑程序,有几条linux命令还蛮重要的,总结一下: 1. 直接跑代码: python test.py 2. 若想程序在后台跑,即使本地和服务器断开也能运行: nohup pyt ...
- 获得自己电脑的SSH公匙
关于什么是SSH请点击此"www.Baidu.com”网站了解 我这里只说怎么获取属于自己电脑的SSH公匙 本人是Win10电脑 所以相对来说简单一点 点击win ->选择设置-&g ...
- 区间DP的学习(持续更新)
例题: 1.Multiplication Puzzle 原题地址:http://poj.org/problem?id=1651 2.Dire Wolf 原题地址:http://acm.split.hd ...
- poj3250 Bad Hair Day 单调栈(递减)
Bad Hair Day Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 24420 Accepted: 8292 Des ...
- MySQL设置远程连接服务器
默认情况下,mysql只允许本地登录,如果要开启远程连接,则需要修改/etc/mysql/my.conf文件. 一.修改/etc/mysql/my.conf找到bind-address = 127.0 ...
- CentOS7服务管理(重启,停止,自动启动命令)
我们对service和chkconfig两个命令都不陌生,systemctl 是管制服务的主要工具, 它整合了chkconfig 与 service功能于一体. systemctl is-enable ...
- 数据库分库分表(一)常见分布式主键ID生成策略
主键生成策略 系统唯一ID是我们在设计一个系统的时候常常会遇见的问题,下面介绍一些常见的ID生成策略. Sequence ID UUID GUID COMB Snowflake 最开始的自增ID为了实 ...
- C++中文件流操作
一.C++中流和流操作符 C++中把数据之间的传输操作称为流,流既可以表示数据从内存传送到某个载体或设备中,即输出流,也可以表示数据从某个载体或设备传送到内存缓冲区变量中,即输入流.C++输入输出除了 ...
- Wahrscheinlichkeitstheorie und mathematische Statistik
Übliches Wort 正态分布:Die Normalverteilung 条件概率:Die Bedingte Wahrscheinlichkeit 排列:Die Permutation 组合:D ...