pid=1209">点击打开hdu1209

Problem Description

There is an analog clock with two hands: an hour hand and a minute hand. The two hands form an angle. The angle is measured as the smallest angle between the two hands. The angle between the two hands has a measure that is greater
than or equal to 0 and less than or equal to 180 degrees.



Given a sequence of five distinct times written in the format hh : mm , where hh are two digits representing full hours (00 <= hh <= 23) and mm are two digits representing minutes (00 <= mm <= 59) , you are to write a program that finds the median, that is,
the third element of the sorted sequence of times in a nondecreasing order of their associated angles. Ties are broken in such a way that an earlier time precedes a later time.



For example, suppose you are given a sequence (06:05, 07:10, 03:00, 21:00, 12:55) of times. Because the sorted sequence is (12:55, 03:00, 21:00, 06:05, 07:10), you are to report 21:00.
 

Input

The input consists of T test cases. The number of test cases (T) is given on the first line of the input file. Each test case is given on a single line, which contains a sequence of five distinct times, where times are given in the
format hh : mm and are separated by a single space.
 

Output

Print exactly one line for each test case. The line is to contain the median in the format hh : mm of the times given. The following shows sample input and output for three test cases.
 

Sample Input

3
00:00 01:00 02:00 03:00 04:00
06:05 07:10 03:00 21:00 12:55
11:05 12:05 13:05 14:05 15:05
 
Sample Output
02:00
21:00
14:05

思路:这题主要是求时钟和分钟夹角的大小。然后进行排序。并且还要注意一个小细节问题。当夹角相等时,时间小的放在前面。

夹角求法:分钟旋转一周要60分钟,所以分钟每分钟旋转360度除以60,为6度,而时钟转一周要12小时,一小时等于60分钟,所以分钟转动的速度是时钟转动的12倍。即时钟转动速度为0,5度每分钟。

从而得等公式r=h*30+0.5*m-m*6(h*30:代表时钟准点的度数。而0.5*m:表示转动m分钟时,时钟转动的度数,二者相加即为时钟的总的转的角度。m*6则是分钟转动的角度)

import java.util.Scanner;

public class P1209 {

	public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0){
String s;
String[] str;
int h,m;
Time[] time=new Time[5];
for(int i=0;i<5;i++){
s=sc.next();
str=s.split(":");
h=Integer.parseInt(str[0]);
m=Integer.parseInt(str[1]);
time[i]=new Time(h,m);
}
sort(time);
System.out.printf("%02d:%02d",time[2].h,time[2].m);
System.out.println();
}
} private static void sort(Time[] time) {
for(int i=0;i<time.length-1;i++){
for(int j=0;j<time.length-1-i;j++){
if(time[j].r>time[j+1].r){
swap(time,j,j+1);
}else if(time[j].r==time[j+1].r){
if(time[j].h>time[j+1].h){
swap(time,j,j+1);
}
}
}
}
} private static void swap(Time[] time, int j, int i) {
Time t=new Time();
t=time[j];
time[j]=time[i];
time[i]=t;
} }
class Time{
public int h;
public int m;
public double r;
public Time(int h,int m){
this.h=h;
this.m=m;
setR();
}
private void setR() {
this.r=Math.abs(h%12*30.0+m*0.5-m*6.0);
if(this.r>180){
this.r=360-this.r;
}
}
public Time(){ }
}

hdu1209(Clock)的更多相关文章

  1. hdoj 5387(Clock)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5387 比较水的一道题目,也是自己单翘的第一道题目吧,题意就是找到给定时间时钟三个指针之间的夹角, 需要 ...

  2. linux入门基础_centos(一)--基础命令和概念

    闲来无事干,看看2014自己整理的一些学习笔记.独乐了不如众乐乐吗! 贴出来和大家分享一下,由于篇幅比较长,分成几篇发布吧,由于是学习笔记,可能有些地方写的不是很正确或者说不详细,或者你会看到上面的课 ...

  3. Java8新特性(转载)

    1.Lambda表达式 Lambda表达式(也称为闭包)是整个Java 8发行版中最受期待的在Java语言层面上的改变.使用 Lambda 表达式可以使代码变的更加简洁紧凑. Lambda允许把函数作 ...

  4. java1.8新特性整理(全)

    版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/yitian_66/article/deta ...

  5. Ceisum官方教程2 -- 项目实例(workshop)

    原文地址:https://cesiumjs.org/tutorials/Cesium-Workshop/ 概述 我们很高兴欢迎你加入Cesium社区!为了让你能基于Cesium开发自己的3d 地图项目 ...

  6. Flink架构(三)- 事件-时间(Event-Time)处理

    3. 事件-时间(Event-Time)处理 在“时间语义”中,我们强调了在流处理应用中时间语义的重要性,并解释了处理时间与事件时间的不同点.处理时间较好理解,因为它基于本地机器的时间,它产生的是有点 ...

  7. Cesium应用篇:3控件(1)Clock

    创建 跟Clock相关的主要有Animation控件和Timeline控件,通常两者会放在一起使用. 在Cesium中,Viewer默认开启这两个控件,如果你想要不显示控件,可以在Viewer初始化中 ...

  8. Linux时间子系统之(五):POSIX Clock

    专题文档汇总目录 Notes: 本章主要介绍了若干种类的静态时钟,这些时钟都可以通过k_clock表示,注册到posix_clocks中.这些都是静态时钟,可以分为三大类:各种REALTIME时钟.带 ...

  9. 操作系统笔记(六)页面置换算法 FIFO法 LRU最近最久未使用法 CLOCK法 二次机会法

    前篇在此: 操作系统笔记(五) 虚拟内存,覆盖和交换技术 操作系统 笔记(三)计算机体系结构,地址空间.连续内存分配(四)非连续内存分配:分段,分页 内容不多,就不做index了. 功能:当缺页中断发 ...

随机推荐

  1. c#调用带有自定义表结构的存储过程

    1.新建自定义表结构 CREATE TYPE [dbo].[HBForHBGHDR] AS TABLE( [序号] [int] NULL, [客户编号] [varchar](15) NULL ) GO ...

  2. springboot 的一般配置

    import javax.servlet.Filter; import org.springframework.boot.SpringApplication; import org.springfra ...

  3. Spring Boot (7) JdbcTemplate访问数据库

    使用jdbcTemplate操作数据库 spring framework对数据库的操作在jdbc上面做了深层次的封装,通过依赖注入功能,可以将datasource注册到jdbcTemplate中,学习 ...

  4. div自动适应浏览器窗口水平和垂直居中

    html <body> <div id="centerDiv">自动适应水平和垂直居中</div> </body> css ;;} ...

  5. C#让电脑发声,播放声音

    //1. [DllImport("Kernel32.dll")] //引入命名空间 using System.Runtime.InteropServices; public sta ...

  6. Morse理论:拓扑不变性特征匹配原理

    设计精美的宽基线双目相机镇文 Mo'ersi lilun莫尔斯理论(卷名:数学) Morse theory 微分拓扑的一个重要分支.通常是指两部分内容:一部分是微分流形上可微函数的莫尔斯理论,即临界点 ...

  7. 连接(JOIN)运算

    内连接--INNER JOIN 此处用商品表(product)和商店商品表(ShopProduct)测试,外键:product_id select sp.shop_id, sp.shop_name, ...

  8. vue-属性传值 props

    props属性传值 1.传具体的值  string(字符串) number(数值) boolean(布尔) 2.传一个引用 array(数组)  object(对象) ----传引用----- 代码 ...

  9. Django 框架入门

    1.创建虚拟环境.(如果你想在你的服务器中运行多个项目,那么装虚拟环境是最好的选择) pip install virtualenv pip install virtualenvwrapper 安装好后 ...

  10. Java 动态实现word导出功能

    1.word模板:xx.ftl生成,ftl文件就是word的源代码,类似html一样是拥有标签和样式的代码. 把需要导出的doc文件模板用office版本的word工具打开. 把doc文件另存为xx. ...