Codeforces816A Karen and Morning 2017-06-27 15:11 43人阅读 评论(0) 收藏
2 seconds
512 megabytes
standard input
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.
The first and only line of input contains a single string in the format hh:mm (00 ≤ hh ≤ 23, 00 ≤ mm ≤ 59).
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.
05:39
11
13:31
0
23:59
1
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.
————————————————————————————————
题目的意思是给你一个时间,问过了多少时间才会让现在时间变成回文
模拟时间流逝 每一秒判一次是否回文
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath> using namespace std; #define LL long long
const int inf=0x7fffffff; bool check(int h,int m)
{
if(h/10+(h%10)*10==m)
return 1;
return 0;
}
int main()
{
int h,m;
while(~scanf("%d:%d",&h,&m))
{
int ans=0;
while(!check(h,m))
{
ans++;
m++;
if(m==60)
h+=1,m=0;
if(h==24)
h=0;
}
printf("%d\n",ans); } return 0;
}
或者干脆蠢一点根据时间分类讨论
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath> using namespace std; #define LL long long
const int inf=0x7fffffff; int main()
{
int h,m;
while(~scanf("%d:%d",&h,&m))
{
int t=h*60+m;
int ans;
if(h<5||(h==5&&m<=50))
{
int fm=h*10;
if(m<=fm)
{
ans=fm-m;
}
else
{
fm=(h+1)*10;
ans=(h+1)*60+fm-t;
}
}
else if(h<=9)
{
ans=10*60+1-t;
}
else if(h<15||(h==15&&m<=51))
{
int fm=(h%10)*10+(h/10);
if(m<=fm)
{
ans=fm-m;
}
else
{
fm=((h+1)%10)*10+((h+1)/10);
ans=(h+1)*60+fm-t;
}
}
else if(h<=19)
{
ans=20*60+2-t;
}
else if(h<23||(h==23&&m<=32))
{
int fm=(h%10)*10+(h/10);
if(m<=fm)
{
ans=fm-m;
}
else
{
fm=((h+1)%10)*10+((h+1)/10);
ans=(h+1)*60+fm-t;
}
}
else
{
ans=24*60-t;
}
printf("%d\n",ans);
}
return 0;
}
Codeforces816A Karen and Morning 2017-06-27 15:11 43人阅读 评论(0) 收藏的更多相关文章
- SQL 存储过程 分页 分类: SQL Server 2014-05-16 15:11 449人阅读 评论(0) 收藏
set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go -- ============================================= -- Au ...
- save与Update的合并操作 标签: 关系映射 2017-07-13 15:11 7人阅读 评论(0) 收藏
做save与update的方法合并操作时,判断条件是主体对象的ID是否存在. 但是当页面中,涉及到多个主体对象的关联对象时,情况变得复杂起来,特总结项目中的几点 一.页面中的VO对象属性可以分为三类: ...
- 【JAVA编码专题】总结 分类: B1_JAVA 2015-02-11 15:11 290人阅读 评论(0) 收藏
第一部分:编码基础 为什么需要编码:用计算机看得懂的语言(二进制数)表示各种各样的字符. 一.基本概念 ASCII.Unicode.big5.GBK等为字符集,它们只定义了这个字符集内有哪些字符,以及 ...
- 安装hadoop1.2.1集群环境 分类: A1_HADOOP 2014-08-29 15:49 1444人阅读 评论(0) 收藏
一.规划 (一)硬件资源 10.171.29.191 master 10.173.54.84 slave1 10.171.114.223 slave2 (二)基本资料 用户: jediael 目录 ...
- Hadoop常见异常及其解决方案 分类: A1_HADOOP 2014-07-09 15:02 4187人阅读 评论(0) 收藏
1.Shell$ExitCodeException 现象:运行hadoop job时出现如下异常: 14/07/09 14:42:50 INFO mapreduce.Job: Task Id : at ...
- codeforces815A Karen and Game 2017-06-27 15:22 31人阅读 评论(0) 收藏
C. Karen and Game time limit per test 2 seconds memory limit per test 512 megabytes input standard i ...
- Codeforces816B Karen and Coffee 2017-06-27 15:18 39人阅读 评论(0) 收藏
B. Karen and Coffee time limit per test 2.5 seconds memory limit per test 512 megabytes input standa ...
- PIE(二分) 分类: 二分查找 2015-06-07 15:46 9人阅读 评论(0) 收藏
Pie Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submissio ...
- Basic 分类: POJ 2015-08-03 15:49 3人阅读 评论(0) 收藏
Basic Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 905 Accepted: 228 Description The p ...
随机推荐
- fedora25的免密码rsync服务配置
目标:实现免密同步数据: 1.安装rsync包: 2.手工添加配置文件: cat /etc/rsyncd.conf # See rsyncd.conf man page for more opt ...
- 10分钟搭建 App 主流框架
搭建主流框架界面 0.达成效果 我们玩iPhone应用的时候,有没发现大部分的应用都是上图差不多的结构,下面的TabBar控制器可以切换子控制器,上面又有Navigation导航条 我们本文主要是搭建 ...
- java中的内存模型
概述 Java平台自动集成了线程以及多处理器技术,这种集成程度比Java以前诞生的计算机语言要厉害很多,该语言针对多种异构平台的平台独立性而使用的多线程技术支持也是具有开拓性的一面,有时候在开发Jav ...
- HDU 4455.Substrings
Substrings Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- Python generator 的yield (enumerate)
生成杨辉三角 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 def triangles(max): L = [1,] while len(L) - 1 < ...
- sqli-labs:17,增删改
增 insert into users values(','lcamry','lcamry'); 删 delete from users where id=16 删数据库:drop database ...
- 记录点复习题目和linux学习
哈希怎么底层.key放数组哪部分里面 HashMap实际上是一个“链表散列”的数据结构,即数组和链表的结合体. 开网页怎么获取页面 linux 看进程的cpu 和内存占用率 看哪个端口被占用 ...
- mysql 5.7.10 下互为主备配置
mysql安装方法这里就不在介绍,网上有很多教程 环境介绍: A主机: win2008_x64+mysql5.7.10 64位,ip192.168.7.180 B主机: win2008_x64+mys ...
- python - package - bs4 - 美味汤
Beautiful Soup 3 only works on Python 2.x, but Beautiful Soup 4 also works on Python 3.x. 你可能在寻找 Bea ...
- Redis的基操
redis:通常BOLEAN操作类型,操作成功返回1,操作失败返回0 通常如果往设置的key插入值,但是这个key不存在,redis则会创建 向redis里的某个key插入多个值时,值和值之间用空格隔 ...