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. 调试和开发npm模块的方式

    ln -s(软连接) 假设my-project是运行npm模块的项目,vue-router是我们需要调试的npm模块 将vue-router下载到与my-project同级目录中. git clone ...

  2. javascript提高篇

    本章简介 本章内容比较少,有三个分享的知识.你可能都看过了,因为网上也有很多提问和解答,如果没看过或者没搞懂,你可以再看看这篇文章. 1. 数组去重方法的演变    --  走向代码缩短化 2. [] ...

  3. Beta阶段第2周/共2周 Scrum立会报告+燃尽图 04

    此作业要求参见https://edu.cnblogs.com/campus/nenu/2018fall/homework/2412 版本控制地址    [https://git.coding.net/ ...

  4. 2018软工实践—Alpha冲刺(3)

    队名 火箭少男100 组长博客 林燊大哥 作业博客 Alpha 冲鸭鸭鸭! 成员冲刺阶段情况 林燊(组长) 过去两天完成了哪些任务 协调各成员之间的工作 协助后端界面的开发 搭建项目运行的服务器环境 ...

  5. Web站点性能-微观手段

    文章:网站性能优化 百度百科:高性能Web站点 文章:构建高性能WEB站点之 吞吐率.吞吐量.TPS.性能测试

  6. Beta结束感想

    我得到的: 管理一个9人团队的经验 与组内成员(大部分一开始并不认识)共同向同一个目标努力的宝贵经历 学会使用Github的organization来管理整个团队的代码 学会使用leangoo这样的协 ...

  7. Eclipse 如何安装反编译插件

    安装反编译插件 1.Help——Eclipse Marketplace 2.输入 Decompiler 搜索并安装此插件 3.根据提示无脑下一步,安装好,重启后(如果还是无法编译,需要把默认打开cla ...

  8. 3dContactPointAnnotationTool开发日志(三三)

      添加背景图片后发现Runtime Transform Gizmo无法选中物体了:   于是改了一下EditorObjectSelection.cs中的WereAnyUIElementsHovere ...

  9. 敏捷冲刺DAY5

    一. 每日会议 1. 照片 2. 昨日完成工作 发布和提供需求功能的实现 用户修改自己的信息 用户界面设计 管理员界面设计 3. 今日完成工作 4. 工作中遇到的困难 1.设置的背景无法显示. 2.一 ...

  10. CCF——图像旋转201503-1

    问题描述 旋转是图像处理的基本操作,在这个问题中,你需要将一个图像逆时针旋转90度. 计算机中的图像表示可以用一个矩阵来表示,为了旋转一个图像,只需要将对应的矩阵旋转即可. 输入格式 输入的第一行包含 ...