Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) A. Broken Clock 水题
A. Broken Clock
题目连接:
http://codeforces.com/contest/722/problem/A
Description
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39
Input
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Sample Input
24
17:30
Sample Output
17:30
Hint
题意
12小时制的话,时钟是从1开始到12的。
24小时制的话,时钟是从0开始到23的
然后给你一个小时制度,然后再给你一个时间,问你这个时间是否合法,如果不合法的话,你需要修改最少的数字,使得这个时间合法 。
题解:
智力低下的人,就像我一样,直接暴力枚举就好了,不要去想那么多……
代码
#include<bits/stdc++.h>
using namespace std;
int main()
{
int h;scanf("%d",&h);
string s;cin>>s;
int ans1 = 1e9;
string ans2;
if(h==24){
for(int i=0;i<h;i++)
{
for(int j=0;j<60;j++)
{
string s2;
s2+=(i/10)%10+'0';
s2+=i%10+'0';
s2+=':';
s2+=(j/10)%10+'0';
s2+=j%10+'0';
int tmp = 0;
for(int k=0;k<s2.size();k++)
if(s2[k]!=s[k])tmp++;
if(ans1>tmp)ans1=tmp,ans2=s2;
}
}
}
else
{
for(int i=1;i<=h;i++)
{
for(int j=0;j<60;j++)
{
string s2;
s2+=(i/10)%10+'0';
s2+=i%10+'0';
s2+=':';
s2+=(j/10)%10+'0';
s2+=j%10+'0';
int tmp = 0;
for(int k=0;k<s2.size();k++)
if(s2[k]!=s[k])tmp++;
if(ans1>tmp)ans1=tmp,ans2=s2;
}
}
}
cout<<ans2<<endl;
}
Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) A. Broken Clock 水题的更多相关文章
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) A B C D 水 模拟 并查集 优先队列
A. Broken Clock time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) B. Verse Pattern 水题
B. Verse Pattern 题目连接: http://codeforces.com/contest/722/problem/B Description You are given a text ...
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined)
A. Broken Clock time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined)(set容器里count函数以及加强for循环)
题目链接:http://codeforces.com/contest/722/problem/D 1 #include <bits/stdc++.h> #include <iostr ...
- 二分 Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) D
http://codeforces.com/contest/722/problem/D 题目大意:给你一个没有重复元素的Y集合,再给你一个没有重复元素X集合,X集合有如下操作 ①挑选某个元素*2 ②某 ...
- 线段树 或者 并查集 Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) C
http://codeforces.com/contest/722/problem/C 题目大意:给你一个串,每次删除串中的一个pos,问剩下的串中,连续的最大和是多少. 思路一:正方向考虑问题,那么 ...
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) D. Generating Sets 贪心
D. Generating Sets 题目连接: http://codeforces.com/contest/722/problem/D Description You are given a set ...
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) C. Destroying Array 带权并查集
C. Destroying Array 题目连接: http://codeforces.com/contest/722/problem/C Description You are given an a ...
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) C. Destroying Array
C. Destroying Array time limit per test 1 second memory limit per test 256 megabytes input standard ...
随机推荐
- HTML5 移动开发(CSS3设计移动页面样式)
1.如何创建CSS样式表 2.CSS3的卓越特性 3.基于设备属性改变样式的媒体查询 4.如何使用属性改变元标签创建更美观移动页面 层叠样式表是移动WEB开发中的一个重要组成部分,本次分享将学到如 ...
- 20155338 2016-2017-2 《Java程序设计》第7周学习总结
20155338 2016-2017-2 <Java程序设计>第7周学习总结 教材学习内容总结 本周学习了第十二章和第十三章的内容,我重点学习了第十三章时间与日期的相关内容. 时间的度量: ...
- 20155212 2016-2017-2 《Java程序设计》第6周学习总结
20155212 2016-2017-2 <Java程序设计>第6周学习总结 教材学习内容总结 Chapter10 输入串流为java.io.InputStream,输出串流为java.i ...
- 第11月第21天 php引用 codeigniter cakephp
1. class CI_Controller { private static $instance; /** * Constructor */ public function __construct( ...
- python 入门基础22 --复习 面向对象
面向过程编程思想: 核心:过程 过程指的是解决问题的具体步骤,即先干什么再干什么. 基于该编程思想编写程序,相当于一条流水线,一种机械式的思维方式. 面向对象编程思想: 核心:对象 对象指的是数据与方 ...
- flask基础之Response响应对象(九)
前言 Response对象负责对客户端的响应,每一个请求都会有一个Response对象,那么它在一个请求的声明周期内是怎么发挥作用的呢? Response对象 响应发生的位置 先回顾一下http请求的 ...
- FTP主动/被动原理
FTP 主动模式 1.客户端用大于1024的高位端口发起初始化连接到vsftp服务器的21端口 2.vsftp服务器的21端口主动与客户端大于1024的高位端口建立控制连接 3.vsftp服务器的20 ...
- 【Hadoop】搭建完全分布式的hadoop【转】
转自:http://www.cnblogs.com/laov/p/3421479.html 下面博文已更新,请移步 ↑ 用于测试,我用4台虚拟机搭建成了hadoop结构 我用了两个台式机.一个xp系统 ...
- Phantomjs 抓取、分析某个页面加载时浏览器发起的所有的子请求
var page = require('webpage').create(), system = require('system'), address; if (system.args.length ...
- device-pixel-radio
移动web开发之像素和DPR 今天看到一个面试题,为iphone6s的自适应,答案是@media(min-device-width:414px) and(max-device-width:736px) ...