水题,找误差范围之内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. 关于元素加上margin属性后以谁为基准移动的问题及负margin的问题

    突然想起这个问题,这是很基础很基础的问题啊,但之前很多次都忘记了,然后困扰了我很久.不清不楚的感觉很不好,所以要做成笔记比较好记住,好记性不如烂笔头,以后再次困惑了再回来看看.推荐文章,海玉的< ...

  2. 自己找到的一些比较实用比较好看的前端特效。很多是前面提供的jquery网站的

    http://www.cnblogs.com/zhangzongle/p/6034394.html webservicehttp://blog.csdn.net/wowkk/article/detai ...

  3. CoreJavaE10V1P3.1 第3章 Java的基本编程结构-3.1 Java 最简程序

    3.1Java最简程序 FirstSample.java public class FirstSample { public static void main(String[] args) { Sys ...

  4. [MFC美化] MFC界面UI库总结

    稍微说下自己用过的感受: 1.SkinMagic 动态库DLL使用,(有VC6版本的静态链接库,没能成功调用).对控件:菜单和下拉框(下拉滚动条)有问题.不能自由设置颜色背景 皮肤格式:.smf,可使 ...

  5. webservices(一)

    ---完全摘自网络 什么是webService WebService,顾名思义就是基于Web的服务.它使用Web(HTTP)方式,接收和响应外部系统的某种请求.从而实现远程调用.  1:从WebSer ...

  6. ArrayList构造函数

    //1.摘要: //初始化 System.Collections.ArrayList 类的新实例,该实例为空并且具有默认初始容量. // public ArrayList(); ArrayList a ...

  7. Linux的一些简单命令(二)

    1.查看防火墙状态:service iptables status 2.开启防火墙:service iptables start 3.关闭防火墙:service iptables stop 4.创建目 ...

  8. Beego学习笔记——开始

    beego简介 beego是一个快速开发Go应用的http框架,他可以用来快速开发API.Web.后端服务等各种应用,是一个RESTFul的框架,主要设计灵感来源于tornado.sinatra.fl ...

  9. IOS 加载网络图片2

    //1. NSData dataWithContentsOfURL // [self.icon setImage:[UIImage imageWithData:[NSData dataWithCont ...

  10. ios开发之简单实现loading动画效果

    最近有朋友问我类似微信语音播放的喇叭动画和界面图片加载loading界面是怎样实现的,是不是就是一个gif图片呢!我的回答当然是否定了,当然不排除也有人用gif图片啊!下面我就来罗列三种实现loadi ...