蓝桥杯时钟

在 12 小时制的钟表中, 有分针、时针、秒针来表示时间。记分针和时 针之间的夹角度数为 A(0≤A≤180) 、分针和秒针之间的夹角度数为 (0≤B≤180) 。而恰好在 ss 时 ff 分 mm 秒时, 满足条件 A=2 BA=2B 且 0≤s≤6;0≤f<60;0≤m<60, 请问 s, f, ms,f,m 分别是多少。

请你找出一个 0 时 0 分 0 秒以外的解。

注意时针、分针、秒针都围绕中心匀速转动。

提交格式为三个由一个空格隔开的整数, 分别表示 s, f, ms,f,m 。如 31158 表示 3 点 11 分 58 秒。

public class 钟表 {

	/**
	 * 模拟问题:模拟现实生活中的真实场景
	 * 本题:分析时针、分针、秒针的转动规律 和 两两之间的对应关系
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		//枚举时,分,秒
		double sd,md,hd;
		for(double s=0;s<60;s++) {//秒
			sd=360*s/60;
			for(double m=0;m<60;m++) {//分
				md=360*m/60;
				md+=6*s/60;
				for(double h=0;h<=6;h++) {//时
					hd=360*h/12;
					hd+=30*(m*60+s)/3600;
					
					double A=Math.abs(md-hd);//为符合题目角的范围,避免是优角
					A=Math.min(A, 360-A);
					
					double B=Math.abs(md-sd);
					B=Math.min(B, 360-B);
					if (A==2*B) {
						System.out.println((int)h+" "+(int)m+" "+(int)s);
					}
				}
			}
		}
	}

}

猜你喜欢

转载自blog.csdn.net/weixin_65528063/article/details/130874062