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 ...
随机推荐
- mysql mysqld.sock文件丢失问题
修改mysql 编码为utf8时 在/etc/mysql/目录下 在 [client] 添加 default-character-set=utf8 [mysqld]添加 default-charact ...
- win10上VMare安装Centos7并使用Xshell连接Centos
一.CentOS 使用VMware虚拟机如何上网 1.宿主机的虚拟网关VMnet8的IP设置为自动获取. (1)打开控制面板:“控制面板” ---> “网络和 Internet” ---&g ...
- HTML的报告
import HTMLTestRunner class HTMLReporter(object): def reporter(self,filename,reportername,reporterdi ...
- Python数据库工具类MySQLdb使用
MySQLdb模块用于连接mysql数据库. 基本操作 # -*- coding: utf-8 -*- #mysqldb import time, MySQLdb ...
- tiny cc 编译器,tinycc,变种
去掉了 -run 参数 下载代码和编译好的程序
- Vue热更新报错(log.error('[WDS] Errors while compiling. Reload prevented.'))
log.error('[WDS] Errors while compiling. Reload prevented.');中的WDS其实是webpack-dev-serverwebpack的意思,用来 ...
- 用visual studio 2017来调试python
https://www.visualstudio.com/zh-hans/thank-you-downloading-visual-studio/?sku=Professional&rel=1 ...
- 尝试解决nginx的499错误1
- 《Django By Example》第一章 学习笔记
首先看了下目录,在这章里 将会学到 安装Django并创建你的第一个项目 设计模型(models)并且生成模型(model)数据库迁移 给你的模型(models)创建一个管理站点 使用查询集(Quer ...
- [ASP.NET]使用Layer简介
layer是一款近年来备受青睐的web弹层组件,她具备全方位的解决方案,致力于服务各水平段的开发人员,您的页面会轻松地拥有丰富友好的操作体验. 在与同类组件的比较中,layer总是能轻易获胜.她尽可能 ...