美文网首页程序员
时针、分针和秒针重合问题

时针、分针和秒针重合问题

作者: Sep_D_Dai | 来源:发表于2019-10-27 23:06 被阅读0次

    题目:

        在一天的24小时之中,时钟的时针、分针和秒针完全重合在一起的时候有几次?都分别是什么时间?你怎样算出来的?

    分析:

    先求角速度:(度/秒)

         1. 时针:w1 = 360 / 12*3600 = 1/120 d/s

         2. 分针:w2= 360 / 3600 = 0.1 d/s

        3. 秒针:w3 = 360 / 60 = 6 d/s

     设3个针当中,快针角速度为wf,慢针角速度为ws。若快针在一天24小时中,转k = 0, 1, 2, 3, … , n圈的时候,重合慢针的时间为t,则:

            wf * t - k*360 = ws*t – [ws/wf * k] *360//当一个指针转k圈的时候,另外一个转 [ws/wf * k]圈

             t = 360*( k - [k*ws/wf] ) / (wf - ws)

    代码如下:

    public class Times_Overlap {

        public static void main(String[] args) {

          // TODO Auto-generated method stub

            double w1=1.0/120; //时针角速度

            double w2=0.1,w3=6; //分针、秒针角速度

            time_overlap(w1,w2);

            time_overlap(w2,w3);

        }

        static void time_overlap(double ws,double wf ){

          int n = (int)(24 * 3600 * wf / 360); //快针一共可以转多少圈

          int[] times=new int[n]; int count=1;

          times[0]=0;

          for(int k=0;k<n-1;k++){

              int t =(int)( 360 * (k - (int)(k * ws / wf)) / (wf - ws));         

              if(times[count-1]!=t){times[count]=t;count++;}

          }

        for(int i=0;i<=count;i++){

              int h=times[i]/3600;int m=(times[i]-h*3600)/60;int s=times[i]-h*3600-m*60;

              System.out.print("overlap times are ");

              System.out.print("("+(i+1)+")"+h+":"+m+":"+s+"  "); 

        }

      }

    }

    相关文章

      网友评论

        本文标题:时针、分针和秒针重合问题

        本文链接:https://www.haomeiwen.com/subject/yjzmvctx.html