zoukankan      html  css  js  c++  java
  • UVA-10995 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 andMonny). 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, AC 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.

    A passed C and M at time t1 and t2, respectively, and met D at time t3D met Cand M at times t4 and t5, respectively. The question is: at what time time did Cpass M?

    The input is a sequence of lines, each containing times t1t2t3t4 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.

    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

    Output for sample input

    12:00:00

    11:16:54

    13:37:32

    10:40:00

    题目大意:ACM三人去拜访D,他们处在同一条直线上,位置分布为ACMDACM均以匀速(并不相等)往D的方向前进,D以匀速往ACM的方向前进。

    t1时刻,A超过Ct2时刻A超过Mt3时刻A遇到D,t4时刻C遇到Dt5时刻M遇到D。求C超过M的时刻。其中,t1t2t3t4t5是单调递增的。

    题目解析:不妨将Vd视为0t1时刻时,设|AD|=L,则|CD|=L,则可计算出VcVa。由Va及时刻数据,可算出Vmt2时刻的|CM|。进而算出C超过M的时刻。

    最终推导出的公式为:tx=t2+(t5-t2)*(t4-t3)*(t2-t1)/((t3-t1)*(t5-t2)-(t4-t1)*(t3-t2))

    代码如下:

    # include<iostream>

    # include<cstdio>

    # include<cstring>

    # include<algorithm>

    using namespace std;

    int h[6],m[6],s[6],t[8];

    int main()

    {

    int i,hx,mx,sx;

    char p[10];

    while(scanf("%s",p))

    {

    if(p[0]=='-')

    break;

    h[1]=(p[0]-'0')*10+p[1]-'0';

    m[1]=(p[3]-'0')*10+p[4]-'0';

    s[1]=(p[6]-'0')*10+p[7]-'0';

    for(i=2;i<=5;++i){

    scanf("%d",&h[i]);

    getchar();

    scanf("%d",&m[i]);

    getchar();

    scanf("%d",&s[i]);

    }

    t[0]=0;

    for(i=1;i<=5;++i){

    t[i]=h[i]*3600+m[i]*60+s[i];

    }

    double tx=1.0*(t[5]-t[2])*(t[4]-t[3])*(t[2]-t[1])/(double)((t[3]-t[1])*(t[5]-t[2])-(t[4]-t[1])*(t[3]-t[2]));

    tx+=t[2];

    //cout<<tx<<endl;

    int tt=tx+0.5;

    sx=tt;

    mx=sx/60;

    sx%=60;

    hx=mx/60;

    mx%=60;

    printf("%02d:%02d:%02d ",hx,mx,sx);

    }

    return 0;

    }

  • 相关阅读:
    Vue.js中使用iView日期选择器并设置开始时间结束时间校验
    侠客行
    myJRebel 已不可用
    开发.NET Core NuGet包并实现CI/CD
    独立部署GeoWebCache
    GeoServer中GeoWebCache(GWC)的使用
    使用VS Code编写Markdown文件
    GitHub团队协作流程
    打包发布到NPM并通过CDN访问
    使用VS Code编写Markdown文件
  • 原文地址:https://www.cnblogs.com/20143605--pcx/p/4672471.html
Copyright © 2011-2022 走看看