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 ...
随机推荐
- Leaving Auction
Leaving Auction 题目链接:http://codeforces.com/contest/749/problem/D 二分 本来以为是哪种神奇的数据结构,没想到sort+lower_bon ...
- json格式化和查看工具
以前一直以来都觉得xml个可读性要比json的可读性好,后来使用了JSON Viewer这个小工具之后,发现自己错了.之前认为json的可读性差,完全是因为没有很好的查看工具.JSON Viewer这 ...
- AR/VR行业是否会像智能手机一样的飞速崛起
从硬件和内容两方面来看,VR(虚拟现实)应该会比AR(增强现实)率先普及大众.当然,这是建立在解决无线化.眩晕.便携等问题之后的事儿,内容上不用担心,照现在这个发展速度-- 说到"风口&qu ...
- Runloop与autoreleasePool联系
autoreleasePool自动释放池,ARC模式下,苹果会自动进行内存管理,不需要我们手动去管理内存.这对于苹果开发者来说,省去了很多事情,不用再每天为了内存管理浪费掉宝贵的开发时间.大家都知道, ...
- SpringMVC @ResponseStatus 的用法
@ResponseStatus 用于修饰一个类或者一个方法,修饰一个类的时候,一般修饰的是一个异常类,如下, 声明一个异常类在类上面加上ResponseStatus注解,就表明,在系统运行期间,抛出A ...
- .net: 不能忽视的break——寻找VS2010和VS2012编译器的一个小区别
文中的问题来自于实际开发,但是实际开发中的代码逻辑比较复杂,因此下面的代码去掉了所有逻辑,只保留能体现问题的代码,类和都只为了说明问题,并不具有实际意义.下面首先看看下面的代码和现象. 1. 问题再现 ...
- sqlcipher for android
github 地址 https://github.com/sqlcipher/android-database-sqlcipher 官网教程 https://www.zetetic.net/sqlci ...
- android下拉刷新控件 android-pulltorefresh
运行效果: 介绍:ListView.ViewPager.WevView.ExpandableListView.GridView.(Horizontal)ScrollView.Fragment上下左右拉 ...
- BZOJ 1303 【CQOI2009】中位数图
baidu了一下bzoj水题列表...找到这道题. 题目大意:给定一个数t,在给定的一段包含1-n的序列中找出多少个长度为奇数子序列的中位数为t. 第一眼没看数据范围,于是开心的打了一个O(n^3 ...
- hdu1029
#include<iostream>#include<string.h>using namespace std;int main(){ int n,i; int t; int ...