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张卡片,定义一张卡片能打败另一张卡片当且仅当它的至少两项属性要严格大于另一张的对应属 ...
随机推荐
- javascript-初级-day02-this关键字
day01-获取元素的第二种方法 <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-T ...
- pcm-pcie 解析
简介 pcm 全称为 Performance Counter Monitor,该项目是针对 intel 平台处理器的资源利用率进行监控的工具.在现代 Intel 处理器已经提供了监视处理器内部性能事件 ...
- 【基因组组装】HiC挂载Juicebox纠错补充
目录 1. 主要纠错类型 misjoins translocations inversions chromosome boundaries 2. 其他有用操作 撤销与反撤销 移到边角料 1. 主要纠错 ...
- 用Rsync实现windows下同步linux服务器的数据
一:环境 1.服务端:Red Hat Enterprise Linux Server release 6.4 (Santiago) 2.客户端:windows7旗舰版64位 3.同步对象:测试数据 4 ...
- Python与Perl的相似与差别
Python version 3.7版本 00.命令行交互 命令行交互 Perl Python perl -e <Perl代码> #Unix/Linux/Windows/DOS 直 ...
- header 301,显示302
header 301,显示302 一定要注意Location 后面的":"前后都不能有空格 header('HTTP/1.1 301 Moved Permanently'); he ...
- 关于蓝牙Mesh您必须知道的七件事
蓝牙技术联盟于7月19日正式宣布,蓝牙(Bluetooth)技术开始全面支持Mesh网状网络.全新的Mesh功能提供设备间多对多传输,并特别提高构建大范围网络覆盖的通信能力,适用于楼宇自动化.无线传感 ...
- Linux 内存泄漏 valgrind
Valgrind 是个开源的工具,功能很多.例如检查内存泄漏工具---memcheck. Valgrind 安装: 去官网下载: http://valgrind.org/downloads/curre ...
- 位运算符在JS中的妙用
正文 位运算 JavaScript 中最臭名昭著的 Bug 就是 0.1 + 0.2 !== 0.3,因为精度的问题,导致所有的浮点运算都是不安全的,具体原因可详见<0.1 + 0.2不等于0. ...
- 【leetocde】922. Sort Array By Parity II
Given an array of integers nums, half of the integers in nums are odd, and the other half are even. ...