博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UVA-10995 Educational Journey
阅读量:4563 次
发布时间:2019-06-08

本文共 2781 字,大约阅读时间需要 9 分钟。

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\n",hx,mx,sx);

}

return 0;

}

转载于:https://www.cnblogs.com/20143605--pcx/p/4672471.html

你可能感兴趣的文章
python 虚拟环境的 安装与 使用 和修改为豆瓣源
查看>>
js 快速入门
查看>>
Python 中的GIL
查看>>
如何解决ASCII 字符显示不出来的情况
查看>>
制表符 \t 的用法
查看>>
断点模式
查看>>
Ubuntu 侧边栏和顶栏设置
查看>>
底层原理
查看>>
21. Merge Two Sorted Lists
查看>>
shiro设置加密算法源码解析
查看>>
第二次冲刺
查看>>
实验四
查看>>
win8.1镜像制作
查看>>
Windows 服务开发框架介绍 - Topshelf
查看>>
php,字符串(二)
查看>>
easyui validatebox 验证类型
查看>>
编程迷茫时候看一看
查看>>
“ORA-00913: 值过多”、“ORA-00911: 无效字符”
查看>>
编程中的那些容易迷糊的小知识
查看>>
Sizzle前奏
查看>>