zoukankan      html  css  js  c++  java
  • Educational Journey

           Educational Journey

    The University of Calgary team qualified for the 28th ACM
    International Collegiate Programming Contest World Finals
    in Prague, Czech Republic. Just by using the initials of team
    members they got a very cunning team name: ACM (Alecs,
    Celly and Monny). In order to prepare for the contest, they
    have decided to travel to Edmonton to learn the tricks of trade
    from Dilbert, Alberta-wide famous top-coder.
    Due to a horrible miscommunication which is as welcome
    as a plague among such teams, A, C and M drive from Calgary
    to Edmonton in separate cars. To make things worse,
    there was also a miscommunication with D, who being always
    so helpful, decides to go to Calgary in order to save the team
    a trip to the far, freezing North. All this happens on the same
    day and each car travels at a constant (but not necessarily the
    same) speed on the famous Alberta #2.
    Then A passed C and M at time t1 and t2, respectively,
    and met D at time t3. D met C and M at times t4 and t5,
    respectively. The question is: at what time did C pass M?

    Input
    The input is a sequence of lines, each containing times t1, t2,
    t3, t4 and t5, separated by white space. All times are distinct and given in increasing order. Each time
    is given in the hh : mm : ss format on the 24-hour clock. A line containing ‘-1’ terminates the input.


    Output
    For each line of input produce one line of output giving the time when C passed M in the same format
    as input, rounding the seconds in the standard way.


    Sample Input
    10:00:00 11:00:00 12:00:00 13:00:00 14:00:00
    10:20:00 10:58:00 14:32:00 14:59:00 16:00:00
    10:20:00 12:58:00 14:32:00 14:59:00 16:00:00
    08:00:00 09:00:00 10:00:00 12:00:00 14:00:00
    -1


    Sample Output
    12:00:00
    11:16:54
    13:37:32
    10:40:00

    题意:A,C,M在一条线上,v_a>v_c>v_m.

    AC相遇在t1,AM相遇在t2,A到D的时间为t3,C到D为t4,M到d为t5

    求CM相遇的时间

    tip:注意时间是时刻,不是时间段,不是经过多少时间才到的;

      数学运算得:t=(v_a-v_d)*(t2-t1)/(v_c-v_d)+0.5+t1;

      0.5是为了误差,四舍五入;t1是原始要加的

     1 #include<iostream>//wrong
     2 #include<cmath>
     3 #include<cstring>
     4 #include<cstdio>
     5 
     6 using namespace std;
     7 
     8 char ss[100];
     9 int h,m,s;
    10 
    11 int change(char *ss)
    12 {
    13     sscanf(ss,"%d:%d:%d",&h,&m,&s);
    14     return h*3600+m*60+s;
    15 }
    16 
    17 int main()
    18 {
    19     while(scanf("%s",ss)==1&&strcmp(ss,"-1")!=0)
    20     {
    21         double t[10];
    22         memset(t,0,sizeof(t));
    23         t[1]=change(ss);
    24         for(int i=2;i<=5;i++)
    25         {
    26             scanf("%s",ss);
    27             t[i]=change(ss);
    28         }
    29 
    30         double v_c=(t[3]-t[1])/(t[4]-t[1]);
    31         double v_m=(t[3]-t[2])/(t[5]-t[2]);
    32         int ans=(1.0-v_m)*(t[2]-t[1])/(v_c-v_m)+0.5+t[1];
    33 
    34         int ss=ans%60;
    35         ans/=60;
    36         int mm=ans%60;
    37         ans/=60;
    38         int hh=ans%24;
    39         printf("%02d:%02d:%02d
    ",hh,mm,ss);
    40 
    41     }
    42     return 0;
    43 }
  • 相关阅读:
    windows Git安装
    windows 下安装Python
    windows 下安装mongodb及其配置环境
    kafka服务安装-SuSE Linux Enterprise Server 11 SP3
    SUSE Linux 下redis 的坑
    windows 下安装nodejs及其配置环境
    redis服务器安装-SuSE Linux Enterprise Server 11 SP3
    svn服务器搭建-SuSE Linux Enterprise Server 11 SP3
    安装MySQL -- SuSE Linux Enterprise Server 11 SP3
    Git命令参考手册(文本版)
  • 原文地址:https://www.cnblogs.com/moqitianliang/p/4680512.html
Copyright © 2011-2022 走看看