A. Karen and Morning
time limit per test

2 seconds

memory limit per test

512 megabytes

input

standard input

output

standard output

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, because 05: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.

Examples
Input
05:39
Output
11
Input
13:31
Output
0
Input
23:59
Output
1
Note

In 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.

题意:给你一个24时制的时间 判断多少分钟后 是一个回文时间

题解:暴力

 #include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<vector>
using namespace std;
int n;
char a[];
int hh,mm;
int main()
{
scanf("%s",a);
hh=(a[]-'')*+(a[]-'');
mm=(a[]-'')*+(a[]-'');
for(int i=;i<=(*);i++)
{
int nowmm;
int nowhh=hh;
nowmm=mm+i;
nowhh=nowhh+nowmm/;
nowhh%=;
nowmm%=;
nowhh=nowhh/+(nowhh%)*;
if(nowhh==nowmm)
{
printf("%d\n",i);
return ;
}
}
return ;
}
B. Karen and Coffee
time limit per test

2.5 seconds

memory limit per test

512 megabytes

input

standard input

output

standard output

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, 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.

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.

Examples
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
Note

In the first test case, Karen knows 3 recipes.

  1. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive.
  2. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive.
  3. 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.

  1. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree.
  2. 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.

题意:给你 n个区间  q个查询[l,r] 问l~r有多少个值 属于 大于等于k个区间

题解:区间更新姿势+前缀和

 #include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<vector>
using namespace std;
int n,k,q;
map<int,int>l;
int r[];
int ans[];
int main()
{
scanf("%d %d %d",&n,&k,&q);
int s,t;
l.clear();
for(int i=;i<=n;i++)
{
scanf("%d %d",&s,&t);
l[s]++;
l[t+]--;
}
int now=;
for(int i=;i<=;i++)
{
now+=l[i];
r[i]=now;
}
int jishu=;
for(int i=;i<=;i++)
{
if(r[i]>=k)
jishu++;
ans[i]=jishu;
}
for(int i=;i<=q;i++)
{
scanf("%d %d",&s,&t);
printf("%d\n",ans[t]-ans[s-]);
}
return ;
}
C. Karen and Game
time limit per test

2 seconds

memory limit per test

512 megabytes

input

standard input

output

standard output

On the way to school, Karen became fixated on the puzzle game on her phone!

The game is played as follows. In each level, you have a grid with n rows and m columns. Each cell originally contains the number 0.

One move consists of choosing one row or column, and adding 1 to all of the cells in that row or column.

To win the level, after all the moves, the number in the cell at the i-th row and j-th column should be equal to gi, j.

Karen is stuck on one level, and wants to know a way to beat this level using the minimum number of moves. Please, help her with this task!

Input

The first line of input contains two integers, n and m (1 ≤ n, m ≤ 100), the number of rows and the number of columns in the grid, respectively.

The next n lines each contain m integers. In particular, the j-th integer in the i-th of these rows contains gi, j (0 ≤ gi, j ≤ 500).

Output

If there is an error and it is actually not possible to beat the level, output a single integer -1.

Otherwise, on the first line, output a single integer k, the minimum number of moves necessary to beat the level.

The next k lines should each contain one of the following, describing the moves in the order they must be done:

  • row x, (1 ≤ x ≤ n) describing a move of the form "choose the x-th row".
  • col x, (1 ≤ x ≤ m) describing a move of the form "choose the x-th column".

If there are multiple optimal solutions, output any one of them.

Examples
Input
3 5
2 2 2 3 2
0 0 0 1 0
1 1 1 2 1
Output
4
row 1
row 1
col 4
row 3
Input
3 3
0 0 0
0 1 0
0 0 0
Output
-1
Input
3 3
1 1 1
1 1 1
1 1 1
Output
3
row 1
row 2
row 3
Note

In the first test case, Karen has a grid with 3 rows and 5 columns. She can perform the following 4 moves to beat the level:

In the second test case, Karen has a grid with 3 rows and 3 columns. It is clear that it is impossible to beat the level; performing any move will create three 1s on the grid, but it is required to only have one 1 in the center.

In the third test case, Karen has a grid with 3 rows and 3 columns. She can perform the following 3 moves to beat the level:

Note that this is not the only solution; another solution, among others, is col 1, col 2, col 3.

题意:给你一个n*m的矩阵 现在希望用最少的操作 每次操作能使得某一行或者某一列全部减少1  输出最小的操作数 以及操作的过程 无法实现则输出-1

题解:先处理行再处理列 先处理列再处理行 暴力跑两遍  取最优;

 #include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<vector>
using namespace std;
int n,m;
int a[][];
int b[][];
int ans[];
int re[];
int ans1[];
int re1[];
int main()
{
scanf("%d %d",&n,&m);
for(int i=; i<=n; i++)
{
for(int j=; j<=m; j++)
{
scanf("%d",&a[i][j]);
b[i][j]=a[i][j];
}
}
int jishu=;
for(int i=; i<=n; i++)
{
int minx=;
for(int j=; j<=m; j++)
minx=min(minx,a[i][j]);
for(int j=; j<=minx; j++)
{
ans[jishu]=;
re[jishu]=i;
jishu++;
}
for(int j=; j<=m; j++)
{
a[i][j]-=minx;
}
}
for(int i=; i<=m; i++)
{
int minx=;
for(int j=; j<=n; j++)
{
minx=min(minx,a[j][i]);
}
for(int j=; j<=minx; j++)
{
ans[jishu]=;
re[jishu]=i;
jishu++;
}
for(int j=; j<=n; j++)
{
a[j][i]-=minx;
}
}
int flag1=;
for(int i=; i<=n; i++)
{
for(int j=; j<=m; j++)
{
if(a[i][j]!=)
{
flag1=;
break;
}
}
} for(int i=; i<=n; i++)
{
for(int j=; j<=m; j++)
{
a[i][j]=b[i][j];
}
}
int jish=;
for(int i=; i<=m; i++)
{
int minx=;
for(int j=; j<=n; j++)
{
minx=min(minx,a[j][i]);
}
for(int j=; j<=minx; j++)
{
ans1[jish]=;
re1[jish]=i;
jish++;
}
for(int j=; j<=n; j++)
{
a[j][i]-=minx;
}
}
for(int i=; i<=n; i++)
{
int minx=;
for(int j=; j<=m; j++)
{
minx=min(minx,a[i][j]);
}
for(int j=; j<=minx; j++)
{
ans1[jish]=;
re1[jish]=i;
jish++;
}
for(int j=; j<=m; j++)
{
a[i][j]-=minx;
}
}
int flag2=;
for(int i=; i<=n; i++)
{
for(int j=; j<=m; j++)
{
if(a[i][j]!=)
{
flag2=;
break;
}
}
}
if(flag1==&&flag2==)
{
printf("-1\n");
return ;
}
if(flag1==&&flag2==)
{
if(jishu<jish)
{
printf("%d\n",jishu-);
for(int i=; i<jishu; i++)
{
if(ans[i]==)
printf("row ");
else
printf("col ");
printf("%d\n",re[i]);
}
}
else
{
printf("%d\n",jish-);
for(int i=; i<jish; i++)
{
if(ans1[i]==)
printf("row ");
else
printf("col ");
printf("%d\n",re1[i]);
}
}
return ;
}
if(flag1==)
{
printf("%d\n",jishu-);
for(int i=; i<jishu; i++)
{
if(ans[i]==)
printf("row ");
else
printf("col ");
printf("%d\n",re[i]);
}
return ;
}
if(flag2==)
{
printf("%d\n",jish-);
for(int i=; i<jish; i++)
{
if(ans1[i]==)
printf("row ");
else
printf("col ");
printf("%d\n",re1[i]);
}
}
return ;
}
/*
3 2
1 1
2 2
2 2
2 3
2 1 2
2 1 2
*/

Codeforces Round #419 (Div. 2) A B C 暴力 区间更新技巧 +前缀和 模拟的更多相关文章

  1. Codeforces Round #169 (Div. 2) A水 B C区间更新 D 思路

    A. Lunch Rush time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  2. Codeforces Round #538 (Div. 2) F 欧拉函数 + 区间修改线段树

    https://codeforces.com/contest/1114/problem/F 欧拉函数 + 区间更新线段树 题意 对一个序列(n<=4e5,a[i]<=300)两种操作: 1 ...

  3. Codeforces Round #419 (Div. 2) E. Karen and Supermarket(树形dp)

    http://codeforces.com/contest/816/problem/E 题意: 去超市买东西,共有m块钱,每件商品有优惠卷可用,前提是xi商品的优惠券被用.问最多能买多少件商品? 思路 ...

  4. 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 ...

  5. Codeforces Round #419 (Div. 2) A. Karen and Morning(模拟)

    http://codeforces.com/contest/816/problem/A 题意: 给出一个时间,问最少过多少时间后是回文串. 思路: 模拟,先把小时的逆串计算出来: ① 如果逆串=分钟, ...

  6. Codeforces Round #419 (Div. 2)

    1.题目A:Karen and Morning 题意: 给出hh:mm格式的时间,问至少经过多少分钟后,该时刻为回文字符串? 思路: 简单模拟,从当前时刻开始,如果hh的回文rh等于mm则停止累计.否 ...

  7. Codeforces Round #419 Div. 1

    A:暴力枚举第一列加多少次,显然这样能确定一种方案. #include<iostream> #include<cstdio> #include<cmath> #in ...

  8. Codeforces Round #419 (Div. 2) ABC

    python 2.7,用来熟悉Python 由于都是智障题,所以我也不讲述题意和题解,直接贴代码了-- A import sys h,m = map(int,raw_input().split(&qu ...

  9. Codeforces Round #419 (Div. 2) C. Karen and Game

    C. Karen and Game time limit per test 2 seconds memory limit per test 512 megabytes input standard i ...

随机推荐

  1. 基于日志报警插件 elastalert 实现告警

    1.官方http://elastalert.readthedocs.io/en/latest/ 2.报警规则示例 http://elastalert.readthedocs.io/en/latest/ ...

  2. 记因内核版本错误导致U盘不能识别的问题解决

    U盘插上电脑,发现没有自动挂载.然后运行sudo fdisk -l一看,发现并没有U盘所对应的设备,也就是U盘不能识别了!以前从没在Linux上遇到这种问题,通过查资料得知,要识别U盘,需要装载usb ...

  3. New York Comic Con 2013 - 2013年纽约动漫展

    New York Comic Con - 2013年纽约动漫展 New York Comic Con is the largest pop culture event on the East Coas ...

  4. spark的数据结构 RDD——DataFrame——DataSet区别

    转载自:http://blog.csdn.net/wo334499/article/details/51689549 RDD 优点: 编译时类型安全 编译时就能检查出类型错误 面向对象的编程风格 直接 ...

  5. 2017年软件工程第八次作业-互评Alpha版本

    B.Thunder——爱阅app(测评人:方铭) 一.基于NABCD评论作品,及改进建议 每个小组评论其他小组Alpha发布的作品:1.根据(不限于)NABCD评论作品的选题:2.评论作品对选题的实现 ...

  6. 《linux内核与分析》第三周

    20135130王川东 实验:构造一个简单的Linux系统的MenuOS 命令:qemu -kernel linux-3.18.6/arch/x86/boot/bzImage -initrd root ...

  7. YQCB项目介绍

    YQCB记账本软件 制作人:YQCB团队 团队简介:团队成立于2017年11月21日,由陈美琪,张晨阳,邢全阳,刘昭为四人组成. 陈美琪:团队灵魂人物,背负着巨大的压力带起整个团队. 张晨阳:团队领军 ...

  8. Strust2: 工作流程

    以下为Struts2的体系结构图: Struts2框架处理用户请求,大体分为以下几个过程: (1)用户发出一个HttpServletRequest请求 (2)请求经过一系列过滤器,最后达到Filter ...

  9. (五)Jmeter中的属性和变量

    一.Jmeter中的属性: 1.JMeter属性统一定义在jmeter.properties文件中,我们可以在该文件中添加自定义的属性 2.JMeter属性在测试脚本的任何地方都是可见的(全局),通常 ...

  10. Java中int与String间的类型转换

    int -> String int i=12345;String s=""; 除了直接调用i.toString();还有以下两种方法第一种方法:s=i+"" ...