URAL 6089 Nine
水题,找误差范围之内9最多的时间,如果有多个,选择误差最小的一个,如果还有多个,选择字典序最小的一个。同一个时间可以有不同的表示方法,例如60:15也可以表示为59:75。
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
int ansx, ansy;
int mm, ss, i, j;
while (~scanf("%d:%d", &mm, &ss))
{
if (mm == && ss == ) break;
int t = mm * + ss;
int xx, yy;
int maxn = -;
int minn = ;
for (i = ; i <= ; i++)
{
for (j = ; j <= ; j++)
{
int t9 = i * + j;
if ( * abs(t - t9) < t)
{
int sum = ;
xx = i, yy = j;
if (xx / == )sum++;
if (xx % == )sum++;
if (yy / == )sum++;
if (yy % == )sum++;
if (sum>maxn || (abs(t9 - t) < minn&&sum == maxn))
{
ansx = xx; ansy = yy;
maxn = sum;
minn = abs(t9 - t);
}
sum = ;
if (yy < && xx>)
{
xx--;
yy = yy + ;
if (xx / == )sum++;
if (xx % == )sum++;
if (yy / == )sum++;
if (yy % == )sum++;
if (sum > maxn || (abs(t9 - t) < minn&&sum == maxn))
{
ansx = xx; ansy = yy;
maxn = sum;
minn = abs(t9 - t);
}
}
}
}
}
printf("%02d:%02d\n", ansx, ansy);
}
return ;
}
URAL 6089 Nine的更多相关文章
- 后缀数组 POJ 3974 Palindrome && URAL 1297 Palindrome
题目链接 题意:求给定的字符串的最长回文子串 分析:做法是构造一个新的字符串是原字符串+反转后的原字符串(这样方便求两边回文的后缀的最长前缀),即newS = S + '$' + revS,枚举回文串 ...
- ural 2071. Juice Cocktails
2071. Juice Cocktails Time limit: 1.0 secondMemory limit: 64 MB Once n Denchiks come to the bar and ...
- ural 2073. Log Files
2073. Log Files Time limit: 1.0 secondMemory limit: 64 MB Nikolay has decided to become the best pro ...
- ural 2070. Interesting Numbers
2070. Interesting Numbers Time limit: 2.0 secondMemory limit: 64 MB Nikolay and Asya investigate int ...
- ural 2069. Hard Rock
2069. Hard Rock Time limit: 1.0 secondMemory limit: 64 MB Ilya is a frontman of the most famous rock ...
- ural 2068. Game of Nuts
2068. Game of Nuts Time limit: 1.0 secondMemory limit: 64 MB The war for Westeros is still in proces ...
- ural 2067. Friends and Berries
2067. Friends and Berries Time limit: 2.0 secondMemory limit: 64 MB There is a group of n children. ...
- ural 2066. Simple Expression
2066. Simple Expression Time limit: 1.0 secondMemory limit: 64 MB You probably know that Alex is a v ...
- ural 2065. Different Sums
2065. Different Sums Time limit: 1.0 secondMemory limit: 64 MB Alex is a very serious mathematician ...
随机推荐
- Day1 老男孩python自动化运维课程学习笔记
2017年1月7日老男孩python自动化运维课程正式开课 第一天学习内容: 上午 1.python语言的基本介绍 python语言是一门解释型的语言,与1989年的圣诞节期间,吉多·范罗苏姆为了在阿 ...
- 获取Storyboard中的视图控制器
storyboard对于框架的构建是一个非常方便的工具,我们经常需要在storyboard中获取我们指定的视图控制器,那么要怎么获取呢? 方法如下: 第一步:选中视图,为视图自定义一个Storyboa ...
- JNDI中 java:comp/env 的理解
J2EE 上下文环境变量前缀,一般有如下几种:java:/comp/env/jdbcjava:/comp/env/urljava:/comp/env/mailjava:/comp/env/jms在部署 ...
- AngularJs 通过 ocLazyLoad 实现动态(懒)加载模块和依赖-转
http://blog.csdn.net/zhangh8627/article/details/51752872 AngularJs 通过 ocLazyLoad 实现动态(懒)加载模块和依赖 标签: ...
- 同时操作两个数据库:报错Illegal attempt to associate a collection with two open sessions
今天我在一个操作两个数据库的SSH里 同时插入1条数据 报错 Illegal attempt to associate a collection with two open sessions 在这里有 ...
- 开通域名绑定DDNS
一.初衷 我想要有一个自己的域名,然后有自己的server,在server上搭一个网站或者开通一个ftp服务,我想通过这个域名来访问它. 二.什么是DDNS DDNS 动态dns,电信宽带采用拨号联网 ...
- ConfigurationManager 缓存刷新
服务没有停止的情况下,如果修改了配置,如果不刷新,是不会生效的,需要在每次重新读取配置前刷新配置文件,具体如下: ConfigurationManager.RefreshSection("a ...
- HelloMyBLOG!!!
还记得刚辞职的时候,心中满是无助.学习Java的期间让我慢慢重拾信心,带我走出最初的迷茫.如今我已不再是一个人,今后渐渐要开始挑起一个家庭甚至几个家庭的重担.现在也算是在异乡暂时站住了脚跟,虽然离我的 ...
- 相机标定 matlab opencv ROS三种方法标定步骤(2)
二 ubuntu下Opencv的相机标定 一般直接用Opencv的源码就可以进行相机的标定,但是可能只是会实现结果,却不懂实现的过程,我也是模模糊糊的看了<计算机视觉中的多视图几何>以及 ...
- Python学习笔记——基础篇【第五周】——os模块和sys模块
OS模块 提供对操作系统进行调用的接口 os.getcwd() 获取当前工作目录,即当前python脚本工作的目录路径 os.chdir("dirname") 改变当前脚本工作目录 ...