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

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

t1时刻,A超过C,t2时刻A超过M,t3时刻A遇到D,t4时刻C遇到D,t5时刻M遇到D。求C超过M的时刻。其中,t1、t2、t3、t4、t5是单调递增的。

题目解析:不妨将Vd视为0。t1时刻时,设|AD|=L,则|CD|=L,则可计算出Vc,Va。由Va及时刻数据,可算出Vm和t2时刻的|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;

}

UVA-10995 Educational Journey的更多相关文章

  1. 【推公式】UVa 10995 - Educational Journey

    1A~,但后来看人家的代码好像又写臭了,T^T... Problem A: Educational journey The University of Calgary team qualified f ...

  2. OJ题解记录计划

    容错声明: ①题目选自https://acm.ecnu.edu.cn/,不再检查题目删改情况 ②所有代码仅代表个人AC提交,不保证解法无误 E0001  A+B Problem First AC: 2 ...

  3. UVA 437 十九 The Tower of Babylon

    The Tower of Babylon Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Subm ...

  4. UVA - 11374 - Airport Express(堆优化Dijkstra)

    Problem    UVA - 11374 - Airport Express Time Limit: 1000 mSec Problem Description In a small city c ...

  5. POJ 1511 Invitation Cards / UVA 721 Invitation Cards / SPOJ Invitation / UVAlive Invitation Cards / SCU 1132 Invitation Cards / ZOJ 2008 Invitation Cards / HDU 1535 (图论,最短路径)

    POJ 1511 Invitation Cards / UVA 721 Invitation Cards / SPOJ Invitation / UVAlive Invitation Cards / ...

  6. uva 11374 最短路+记录路径 dijkstra最短路模板

    UVA - 11374 Airport Express Time Limit:1000MS   Memory Limit:Unknown   64bit IO Format:%lld & %l ...

  7. UVA 11374 Airport Express SPFA||dijkstra

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  8. uva 1354 Mobile Computing ——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5

  9. UVA 10564 Paths through the Hourglass[DP 打印]

    UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...

随机推荐

  1. nginx反向代理-后端服务器组设置

    nginx服务器的反向代理时其最常用的重要功能之一,在实际工作中应用广泛,涉及的配置指令也比较多.下面会尽量详细地介绍对应的指令,及其使用状态. 反向代理一般是互联网需要向内网拉取资源,比如访问一个w ...

  2. Python Web学习笔记之递归和迭代的区别

    电影故事例证:迭代——<明日边缘>递归——<盗梦空间> 迭代是更新变量的旧值.递归是在函数内部调用自身. 迭代是将输出做为输入,再次进行处理.比如将摄像头对着显示器:比如镜子对 ...

  3. UVA302 John's trip(欧拉回路)

    UVA302 John's trip 欧拉回路 attention: 如果有多组解,按字典序输出. 起点为每组数据所给的第一条边的编号较小的路口 每次输出完额外换一行 保证连通性 每次输入数据结束后, ...

  4. mariadb 10.1查看per connection内存消耗

    在mariadb 10.1版本中,在information_schema.processlist表中,新增了几个字段,其中有一个memory_used,其记录的是连接的内存消耗. 同时新增了一个状态变 ...

  5. 20145327 《网络对抗》逆向及BOF基础实践

    20145327 <网络对抗>逆向及BOF基础实践 实践目标 本次实践的对象是一个名为pwn1的linux可执行文件. 该程序正常执行流程是:main调用foo函数,foo函数会简单回显任 ...

  6. Vue 父组件循环使用refs调用子组件方法出现undefined的问题

    Vue 父组件循环使用refs调用子组件方法出现undefined的问题 1. 背景 最近前端项目遇到一个问题,我在父组件中使用了两个相同的子组件child,分别设置ref为add和update.其中 ...

  7. __NSCFConstantString && __NSPlaceholderDictionary

    一 -[__NSCFConstantString size]: unrecognized selector sent to instance 0x53ea70 该错误是在我将NSString类型的参数 ...

  8. POJ 2785 4 Values whose Sum is 0 (二分)题解

    思路: 如果用朴素的方法算O(n^4)超时,这里用折半二分.把数组分成两块,分别计算前后两个的和,然后枚举第一个再二分查找第二个中是否有满足和为0的数. 注意和有重复 #include<iost ...

  9. ajax用beforeSend自定义请求过程中客户端事件,提高用户体验

    本文为博主原创,未经允许不得转载: 在应用ajax的过程中,当我们再前台提交请求的时候,如果服务端响应事件比较长,就会导致需要等很长时间在前台才能接受到服务端返回的 响应结果,往往会导致用户重复点击按 ...

  10. OpenVirteX 创建简易虚拟网络

    OpenVirteX 创建简易虚拟网络 1.打开OVX sh OpenVirteX/script/ovx.sh 2.创建mininet物理拓扑 1sw, 2hosts mn --controller= ...