水题,找误差范围之内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. C语言之break和continue

    一 break 和 continue 的介绍 break: 1).跳出当前所在的switch语句(tips:可查看前面 switch 部分)   2).跳出当前所在的循环 continue: 结束本次 ...

  2. python之路 - 基础3

    1.字符串处理 name = "my name is jiachen" #首字母大写 print (name.capitalize()) #统计字母出现次数 print (name ...

  3. Flexible 弹性盒子模型之CSS justify-content 属性

    实例 在弹性盒对象的 <div> 元素中的各项周围留有空白: div { display: flex; justify-content: space-around; } 复制 效果预览 浏 ...

  4. HTTP协议----ETag

    Etag是URL的Entity Tag,用于标示URL对象是否改变,区分不同语言和Session等等.具体内部含义是服务器控制的,就像Cookie那样. 服务器首先产生ETag,服务器可在稍后使用它来 ...

  5. [pinyin4j] java版汉字转换拼音(大小写)

    pinyin4J 是一个可以将汉字转换成拼音的lib,非常实用,其maven地址为:http://mvnrepository.com/artifact/com.belerweb/pinyin4j/2. ...

  6. 一台服务器上同时启动多个 Tomcat

    在同一台服务器上启动多个 Tomcat 服务,需要修改 conf/server.xml文件里的三个部分,如下: 1.修改Http访问端口(默认为8080端口) <Connector port=& ...

  7. 【锋利的Jquery】读书笔记五

    jquery表单 表格操作 表单从基本的得到和失去焦点表单验证 <script type="text/javascript"> $(function(){ $(&quo ...

  8. C#扩充类

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  9. java--调整JVM内存的大小

    默认占用:64M的内存 修改内存的方式: 1.某一类,右键选择--Run Configurations 2.选择--Arguments 3.在VM argments中输入内容,如:-Xmx80m

  10. Reprint: Serialization

    Having just recently ran into some major serialization issues I’m going to list some of the errors a ...