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 ...
随机推荐
- (转)silverlight应用程序中未处理的错误代码:2104 类别:InitializeError
解决方案:第一步:默认网站--属性-----http头 第二步:点击mime类型: 第三步:点击新建: 第四步:输入扩展名以及类型: (1) 扩展名:.xaml MIME类型:applicat ...
- php 多进程
php 在使用场景中一般是处理web应用,所以多进程使用不适合在web中使用,且php-fpm中pcntl_fork不能使用,所以使用场景是在cgi模式下 一个进程调用pcntl_fork函数后,系统 ...
- iOS.NS_DEPRECATED_IOS
如何处理被NS_DEPRECATED_IOS标记的selector, 例如:类 AVAudioSession中有: - (BOOL)setPreferredHardwareSampleRate:(do ...
- this 关键字 详解
JS中的this关键字让很多新老JS开发人员都感到困惑.这篇文章将对this关键字进行完整地阐述.读完本文以后,您的困惑将全部消除.您将学会如何在各种不同的情形正确运用this. 我们和在英语.法语这 ...
- (O)JS核心:call、apply和bind
1. var func=function(a,b,c){ console.log([a,b,c]); }; func.apply(null,[1,2,3]); //[1,2,3] func.call( ...
- RAPID程序设计
1.ABB机器人软件 RobotWare 是ABB提供的机器人系列应用软件的总称. RobotStudio是ABB公司自行开发的机器人模拟软件, 能在PC机上模拟几乎所有型号的ABB 机器人几乎所有的 ...
- 伪静态的服务器配置-如何php为 Discuz! X2 配置伪静态
URL 静态化是一个有利于搜索引擎的设置,通过 URL 静态化,达到原来是动态的 PHP 页面转换为静态化的 HTML 页面,可以提高搜索引擎抓取,当然,这里的静态化是一种假静态,目的只是提高搜索 ...
- 进化树(phylogenetic trees)
构建进化树的工具有: muscle mega 进化树的可视化: 本地可视化软件 Figtree (网址:http://tree.bio.ed.ac.uk/software/figtree/) 该软件是 ...
- spring.boot mybaits集成
https://www.cnblogs.com/pejsidney/p/9272562.html (insertBatch批量插入) 第一篇博客循环部分有错误,参照下面的例子去更改 List<S ...
- Ubuntu下Tomcat绑定80端口(zz)
Ubuntu下Tomcat绑定80端口 来源:本站转载 作者:佚名 时间:2011-02-22 TAG: 工作环境迁移到了Ubuntu,很多东西发生了变化,比如原先配置tomcat端口.只需要配置se ...