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张卡片,定义一张卡片能打败另一张卡片当且仅当它的至少两项属性要严格大于另一张的对应属 ...
随机推荐
- vscode 整理————开篇之力(一)
前言 作为一个开发为什么对一个vscode 这样的工具进行整理呢,因为vscode 非常的常用,它包含很多编辑器共同有的特征,这些特征帮助我们了解其他编辑器. 这里可能就有人疑问了,我们需要去非常的关 ...
- Pulsar云原生分布式消息和流平台v2.8.0
Pulsar云原生分布式消息和流平台 **本人博客网站 **IT小神 www.itxiaoshen.com Pulsar官方网站 Apache Pulsar是一个云原生的分布式消息和流媒体平台,最初创 ...
- 超算云(GPU服务器)环境配置
最近在用并行超算云GPU服务器(中国国家网格12区)搭建毕设的环境,这里记录一下. 首先,超算云服务器的登录可以采用网页版.也可以采用客户端(超算云地址:https://cloud.paratera. ...
- CODING 代码资产安全系列之 —— 构建全链路安全能力,守护代码资产安全
本文作者:王振威 - CODING 研发总监 CODING 创始团队成员之一,多年系统软件开发经验,擅长 Linux,Golang,Java,Ruby,Docker 等技术领域.近两年来一直在 COD ...
- P6585 中子衰变
我们偶数的时候只要对称操作. 奇数的话,我们定义\(1\)的相反数为\(-1\),\(0\)相反数为\(0\). 我们维护最长的两边的相反串,中间一段除了一个端点,其他均被染成同色. 那么如果对方染端 ...
- 【豆科基因组】大豆(Soybean, Glycine max)泛基因组2020Cell
目录 一.前沿概述 二.主要结果 重测序.组装与注释 泛基因组 SV特征 PAV与古多倍化,WGD事件 基因SV与基因融合 SV与大豆驯化 SV影响基因表达及其与性状关联 一.前沿概述 Pan-Gen ...
- 【Linux】【Shell】【Basic】一行代码解决常见问题
1. 查看可用IP for i in `seq 1 255`; do ping -c 1 10.210.55.$i >> /dev/null; if [ $? -eq 1 ]; then ...
- oracle to_char处理日期
select to_char(sysdate,'d') from dual;--本周第几天 select to_char(sysdate,'dd') from dual;--本月第几天 select ...
- Oracle decode和case的区别
case在SQL中有两种写法,先建立一个表create table salgrade(grade int, sal int);insert into salgrade values(1,1000);i ...
- tableView和tableViewCell的背景颜色问题
当在tableView中添加cell数据时,我们会发现原本设置的tableView的背景颜色不见了,这是因为加载cell数据时,tableView的背景颜色被cell数据遮盖住了,此时,可以通过设置c ...