CF816A Karen and Morning 题解
Content
给定一个时间 \(h:m\),求从现在这个时间开始到下一个离该时间最近的回文时间要多久?
数据范围:\(0\leqslant h\leqslant 23,0\leqslant m\leqslant 59\)。
Solution
其实 scanf 有个特别的技巧叫做按格式读入,比如说这里我们就可以用 scanf("%d:%d", ...); 来按照 \(h:m\) 的格式读入。
然后,正如我在 CF108A 的题解里面讲的那样,一共的回文时间只有 \(16\) 个(具体是哪几个自己点进去看),所以先判断是否是回文,然后再往后一步一步地推时间就好了。
这题貌似和 CF108A 差不多,只是要求的不是具体的时间而是过了多久罢了。
Code
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#define _for(i, a, b) for(int (i) = (a); (i) <= (b); ++(i))
#define _rep(i, a, b) for(int (i) = (a); (i) >= (b); --(i))
using namespace std;
typedef long long ll;
inline void getint(int& x) {
int f = 1; x = 0;
char c = getchar();
while(!isdigit(c)) {if(c == '-') f = -1; c = getchar();}
while(isdigit(c)) {x = x * 10 + c - '0'; c = getchar();}
x *= f;
}
inline void getll(ll& x) {
ll f = 1; x = 0;
char c = getchar();
while(!isdigit(c)) {if(c == '-') f = -1; c = getchar();}
while(isdigit(c)) {x = x * 10 + c - '0'; c = getchar();}
x *= f;
}
inline void writeint(int& x) {
if(!x) {printf("0"); return;}
else if(x < 0) printf("-");
int tmp = x < 0 ? -x : x, digit[17] = {0};
while(tmp) {digit[++digit[0]] = tmp % 10; tmp /= 10;}
_rep(i, digit[0], 1) printf("%d", digit[i]);
}
inline void writell(ll& x) {
if(!x) {printf("0"); return;}
else if(x < 0) printf("-");
ll tmp = x < 0 ? -x : x;
int digit[27] = {0};
while(tmp) {digit[++digit[0]] = tmp % 10; tmp /= 10;}
_rep(i, digit[0], 1) printf("%d", digit[i]);
}
int main() {
// freopen(".in", "r", stdin);
// freopen(".out", "w", stdout);
int h, m, ans = 0;
scanf("%d:%d", &h, &m);
while(1) {
if((h == 0 && m == 0) || (h == 1 && m == 10) || (h == 2 && m == 20) || (h == 3 && m == 30) || (h == 4 && m == 40) || (h == 5 && m == 50) || (h == 10 && m == 1) || (h == 11 && m == 11) || (h == 12 && m == 21) || (h == 13 && m == 31) || (h == 14 && m == 41) || (h == 15 && m == 51) || (h == 20 && m == 2) || (h == 21 && m == 12) || (h == 22 && m == 22) || (h == 23 && m == 32)) {
writeint(ans);
break;
}
m++, ans++;
if(m > 59) h++, m = 0;
if(h > 23) h = 0;
}
// fclose(stdin);
// fclose(stdout);
return 0;
}
CF816A Karen and Morning 题解的更多相关文章
- CF815C Karen and Supermarket
题目链接 CF815C Karen and Supermarket 题解 只要在最大化数量的前提下,最小化花费就好了 这个数量枚举ok, dp[i][j][1/0]表示节点i的子树中买了j件商品 i ...
- CF815D Karen and Cards 官方题解翻译
看到这道题,网上没有中文版的官方题解,于是就自己翻译了一遍. 不是机器翻译,是一个字一个字纯手翻译的,如果有错误欢迎指正. 比如我们有一张卡片,三个参数分别是 a1 = 4, b1 = 2, c1 = ...
- B. Karen and Coffee
B. Karen and Coffee time limit per test 2.5 seconds memory limit per test 512 megabytes input standa ...
- C. Karen and Game
C. Karen and Game time limit per test 2 seconds memory limit per test 512 megabytes input standard i ...
- A. Karen and Morning
A. Karen and Morning time limit per test 2 seconds memory limit per test 512 megabytes input standa ...
- 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 ...
- 【CF815D】Karen and Cards 单调栈+扫描线
[CF815D]Karen and Cards 题意:一张卡片有三个属性a,b,c,其上限分别为A,B,C,现在有n张卡片,定义一张卡片能打败另一张卡片当且仅当它的至少两项属性要严格大于另一张的对应属 ...
随机推荐
- [JS高程]JavaScript中的RegExp对象
目录 1. RegExp 1.1 表示格式: 1.2 匹配模式: 1.3 RegExp 实例属性 1.4 RegExp 实例方法 1.4.1 exec() 1.4.1.1 基本用法 1.4.1.2 e ...
- html+css第八篇滑动门和可爱的css精灵
滑动门: 滑动门并不是一项全新的技术,它是利用背景图像的可层叠性,并允许他们在彼此之上进行滑动,以创造一些特殊的效果. CSS精灵 CSS Sprites在国内很多人叫CSS精灵,是一种网页图片应用处 ...
- [Bzoj 1432] [ZJOI2009]Function(结论推导题)
我们先看一下题目: (有没有和我一样的朋友看到这道题以为是几何不可做题 这个题目真的很难理解,并且样例也给得太水了吧! 理解题目是必不可少的(这并不是你看了半小时题目的理由)--首先我们先简化题目 1 ...
- 洛谷 P3721 - [AH2017/HNOI2017]单旋(LCT)
洛谷题面传送门 终于调出来这道题了,写篇题解( 首先碰到这样的题我们肯定要考虑每种操作会对树的形态产生怎样的影响: 插入操作:对于 BST 有一个性质是,当你插入一个节点时,其在 BST 上的父亲肯定 ...
- Perl 语言入门6-9
---- 第6章 哈希----------- 简介 键值对.键和值都是任意标量,但键总是会被转换成字符串. 键唯一,值可重复. 应用场景:一组数据对应到另一组数据时. 如找出重复/唯一/交叉引用/查表 ...
- Linux—yum的python版本错误——高级解决方案
彻底搞明白,python升级后,为什么会导致yum不可用 首先我们来分析下,python升级后,yum为什么会不可用? 先说个关于python的问题,Linux系统很多软件都依赖于python,因此不 ...
- Python | 迭代器与zip的一些细节
首先抛出一个困扰本人许久的问题: nums = [1,2,3,4,5,6] numsIter = iter(nums) for _ in zip(*[numsIter]*3): print(_) pr ...
- 禁止点击、禁止button触发【c#】
bts.Attributes["onclick"] = "return false; ";
- 学习java的第二十五天
一.今日收获 1.java完全学习手册第三章算法的3.2排序,比较了跟c语言排序上的不同 2.观看哔哩哔哩上的教学视频 二.今日问题 1.快速排序法的运行调试多次 2.哔哩哔哩教学视频的一些术语不太理 ...
- act
act的词源是do, 干着或干了的事情也可以叫act.抄全字典的话,抄的和看的都麻烦,在阅读中体会吧. act和action有啥区别?action: doing sth; act: n. action ...