水题,找误差范围之内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的更多相关文章

  1. 后缀数组 POJ 3974 Palindrome && URAL 1297 Palindrome

    题目链接 题意:求给定的字符串的最长回文子串 分析:做法是构造一个新的字符串是原字符串+反转后的原字符串(这样方便求两边回文的后缀的最长前缀),即newS = S + '$' + revS,枚举回文串 ...

  2. ural 2071. Juice Cocktails

    2071. Juice Cocktails Time limit: 1.0 secondMemory limit: 64 MB Once n Denchiks come to the bar and ...

  3. ural 2073. Log Files

    2073. Log Files Time limit: 1.0 secondMemory limit: 64 MB Nikolay has decided to become the best pro ...

  4. ural 2070. Interesting Numbers

    2070. Interesting Numbers Time limit: 2.0 secondMemory limit: 64 MB Nikolay and Asya investigate int ...

  5. ural 2069. Hard Rock

    2069. Hard Rock Time limit: 1.0 secondMemory limit: 64 MB Ilya is a frontman of the most famous rock ...

  6. 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 ...

  7. ural 2067. Friends and Berries

    2067. Friends and Berries Time limit: 2.0 secondMemory limit: 64 MB There is a group of n children. ...

  8. ural 2066. Simple Expression

    2066. Simple Expression Time limit: 1.0 secondMemory limit: 64 MB You probably know that Alex is a v ...

  9. ural 2065. Different Sums

    2065. Different Sums Time limit: 1.0 secondMemory limit: 64 MB Alex is a very serious mathematician ...

随机推荐

  1. 前两篇转载别人的精彩文章,自己也总结一下python split的用法吧!

    前言:前两篇转载别人的精彩文章,自己也总结一下吧! 最近又开始用起py,是为什么呢? 自己要做一个文本相似度匹配程序,大致思路就是两个文档,一个是试题,一个是材料,我将试题按每题分割出来,再将每题的内 ...

  2. 一键强制修改任意Mysql数据库的密码,修改任意环境Mysql数据库。

    本文采用我软件里面的内置改密功能,可以一键强制修改Mysql数据库的密码, 在修改过程中,会强制干掉Mysql主程序,修改完成后重新启动Mysql就可以了. 首先讲解如何一键强制修改PHPWAMP自身 ...

  3. Zookeeper 安装和配置

    单机模式 下载zookeeper的安装包之后, 解压到合适目录. 进入zookeeper目录下的conf子目录, 创建zoo.cfg: tickTime=2000 dataDir=/Users/app ...

  4. python下实现汉诺塔

    汉诺塔是印度一个古老传说的益智玩具.汉诺塔的移动也可以看做是递归函数. 我们对柱子编号为a, b, c,将所有圆盘从a移到c可以描述为: 如果a只有一个圆盘,可以直接移动到c: 如果a有N个圆盘,可以 ...

  5. google的作恶与不作恶

    Google刚刚出现时,那时互联网还似桃花源,路不拾遗夜不闭户,最多升级升级病毒库.Google的发展,从商业模式上带来了广告对互联网无孔不入的渗透,如今Google.百度.阿里等各大巨头都有自己的广 ...

  6. java方法笔记

    1.方法 方法(method),函数(function)//但本质上是一样的--实现特定的功能.程序中完成独立功能,可重复使用的一段代码的集合:方法的格式:[修饰符] 返回值的类型 方法名称([形式参 ...

  7. 64位Java开发平台的选择,如何区分JDK,Tomcat,eclipse的32位与64版本

    当你想下载Linux.JDK.Tomcat.eclipse时,你是下载32位版本还是64位版本?64位版本有两种,应该选哪一个? 当你看到这些内容:x86.x64.x86-32.x86-64.ia64 ...

  8. img 转化成iso镜像的办法

    最近在使用KVM启用虚拟机,然后将里面的环境和配置 配置成我们公司需要的环境,再打包成iso镜像,之后再次生成新的虚拟机. 但是KVM启动出的镜像生成的是img镜像 ,需要将img镜像转换成iso镜像 ...

  9. JUnit——(二)注解

    1. 两种错误:Error和Failure Error是代码错误 @Test publicvoid testAdd() { int z=new T().add(5,3); assertEquals(8 ...

  10. Metrics-Java版的指标度量工具

    介绍 Metrics是一个给JAVA服务的各项指标提供度量工具的包,在JAVA代码中嵌入Metrics代码,可以方便的对业务代码的各个指标进行监控,同时,Metrics能够很好的跟Ganlia.Gra ...