Codeforces Round #419 (Div. 2)
题意:
给出hh:mm格式的时间,问至少经过多少分钟后,该时刻为回文字符串?
思路:
简单模拟,从当前时刻开始,如果hh的回文rh等于mm则停止累计。否则,根据rh和mm的大小来累计sum,然后hh+1,不断尝试。
#include<iostream>
using namespace std;
int main()
{
int hh,mm;
char c;
while (cin >> hh >> c >> mm)
{
int sum = ;
bool firsthour = true;
while ()
{
int rh = hh % * + hh / ;
if (rh == mm) break;
else
{
if (rh < )
{
if (firsthour)
{
firsthour = false;
if (rh >= mm)
{
sum += rh - mm;
break;
}
else
{
sum += - mm;
mm = ;
hh = (hh + ) % ;
}
}
else
{
sum += rh;
break;
}
}
else
{
if (firsthour) sum += - mm,mm=,firsthour=false;
else sum += ;
hh = (hh + ) % ;
} }
}
cout << sum << endl;
}
return ;
}
A. Karen and Morning
题意:
给出n个已知区间,然后询问q个区间,问询问区间中至少被k个已知区间包含的点为几个。
思路:
一开始想着对每个已知区间中的值累加,然后对每次询问[l,r],遍历l——r,妥妥超时~~
然后看了些大神的代码,首先不必要对每个已知区间中的值累加,只要在已知区间的开始和结束的位置做标记,然后对于查询,可以预处理用前缀和来记录1~i满足条件的数目,然后O(1)便能得出答案。还有的巨巨用线段树来维护,至少比O(n)的时间少,应该是O(logn)吧。。。
下面给出巨巨的链接:
Codeforces Round #419 (Div. 2)的更多相关文章
- 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. 1
A:暴力枚举第一列加多少次,显然这样能确定一种方案. #include<iostream> #include<cstdio> #include<cmath> #in ...
- Codeforces Round #419 (Div. 2) ABC
python 2.7,用来熟悉Python 由于都是智障题,所以我也不讲述题意和题解,直接贴代码了-- A import sys h,m = map(int,raw_input().split(&qu ...
- 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 ...
- Codeforces Round #419 (Div. 2) B. Karen and Coffee
To stay woke and attentive during classes, Karen needs some coffee! Karen, a coffee aficionado, want ...
- Codeforces Round #419 (Div. 2)(B)差分数组
传送门:Problem B https://www.cnblogs.com/violet-acmer/p/9721160.html 题意: Karen有n个关于煮咖啡的食谱,每个食谱都有个煮咖啡的最适 ...
- Codeforces Round #419 (Div. 2) A B C 暴力 区间更新技巧 +前缀和 模拟
A. Karen and Morning time limit per test 2 seconds memory limit per test 512 megabytes input standar ...
随机推荐
- 不同浏览器的margin值与padding值
IE-7: 有默认外边距margin样式的元素: dd,menu, ol, ul, blockquote, body, dd, dl, form, h1-6, ul 有默认内边距padding样式的元 ...
- laravel5 事务回滚
方法一 //不需要引入,直接开干 public function Transaction(){ DB::beginTransaction(); //开启事务 $sql1 = DB::table('de ...
- thinkphp 框架中的一部分方法解析
1 thinkphp 框架 中判断输入的数值和数据库中的数值是否一致 首先 需要在view文件夹下建一个模板 名为zhuce.html <html> <head> &l ...
- vlan内部与外部某终端之间的通信
实现虚拟局域网外部终端与内部终端之间的通信,即实现pc3与pc1和pc4之间的通信. 把交换机上的默认VLAN1改成VLAN2(红色字体命令). 各vlan内部终端的通信,是通过vlan ID来实现的 ...
- hdu3336 Count the string kmp+dp
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3336 很容易想到用kmp 这里是next数组的应用 定义dp[i]表示以s[i]结尾的前缀的总数 那么 ...
- XSHELL工具上传文件到Linux以及下载文件到本地(Windows)
Xshell很好用,然后有时候想在windows和linux上传或下载某个文件,其实有个很简单的方法就是rz,sz.首先你的Linux上需要安装安装lrzsz工具包,(如果没有安装请执行以下命令,安装 ...
- String的Intern方法详解
引言 在 JAVA 语言中有8中基本类型和一种比较特殊的类型String.这些类型为了使他们在运行过程中速度更快,更节省内存,都提供了一种常量池的概念.常量池就类似一个JAVA系统级别提供的缓存.8种 ...
- 浅谈 Java Xml 底层解析方式
XML 使用DTD(document type definition)文档类型来标记数据和定义数据,格式统一且跨平台和语言,已成为业界公认的标准. 目前 XML 描述数据龙头老大的地位渐渐受到 Jso ...
- vim 和grep 正则表达式相似和区别
正则表达式由两种基本字符类型组成:原义(正常)文本字符和元字符.元字符使正则表达式具有处理能力.所谓元字符就是指那些在正则表达式中具有特殊意义的专用字符,可以用来规定其前导字符(即位于元字符前面的字符 ...
- jQuery插件ImgAreaSelect 实例讲解二
在上一篇随笔http://www.cnblogs.com/chenguanai/p/6883401.html中,已经了解了头像的上传预览和裁剪功能:那么这次就再看一下imgareaselect的裁剪功 ...