1A~,但后来看人家的代码好像又写臭了,T^T...

Problem A: 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 题意:就是t1,t2,t3,t4,t5分别代表A碰见C,A碰见M,A碰见D,D碰见C,D碰见M(很明显C后来赶超了M),且保证时间依次递增,问C与M相遇的时间;每个人运动的速率为常数且彼此不一定相等。
分析:以D的位置为基准,AC相遇时二者距D的距离相等,用二者分别到达D点的时间差之比求出二者速度之比;同理求出AM速度之比;设CM相遇时时间为tmp,则推出tmp与速度间的表达式。注意计算时需要换成秒计算,且注意数的范围,需用long long。比例运算时可能出现小数,注意四舍五入等精度问题。 臭代码拉出来丢人一下:
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstring>
#include<string>
#define error 1e-8
using namespace std;
typedef long long LL;
const int maxn = ;
string tt[];
struct Time
{
int h, m, s;
}t[];
LL Sub(Time b, Time a)
{
int hh, mm, ss;
if(b.s >= a.s) ss = b.s-a.s;
else
{
ss = b.s+-a.s;
b.m--;
}
if(b.m >= a.m) mm = b.m-a.m;
else
{
mm = b.m+-a.m;
b.h--;
}
hh = b.h-a.h;
return ss+mm*+hh*;
}
LL turn_to_LL(Time x)
{
return x.s+x.m*+x.h*;
}
Time turn_to_time(LL x)
{
Time tmp;
tmp.h = x/; x -= tmp.h*;
tmp.m = x/; x -= tmp.m*;
tmp.s = x;
return tmp;
}
int trans(string s)
{
return *(s[]-'')+(s[]-'');
}
int main()
{
//freopen("in.txt", "r", stdin);
while(cin >> tt[])
{
if(tt[] == "-1") break;
for(int i = ; i < ; i++) cin >> tt[i];
string s;
for(int i = ; i < ; i++)
{
int pos1 = tt[i].find(':'), pos2 = tt[i].find_last_of(':');
s = tt[i].substr(, pos1);
t[i].h = trans(s);
s = tt[i].substr(pos1+, pos2-pos1-);
t[i].m = trans(s);
s = tt[i].substr(pos2+);
t[i].s = trans(s);
}
LL n = Sub(t[],t[])*Sub(t[],t[]);
LL m = Sub(t[],t[])*Sub(t[],t[]); LL tmp = LL(double(m*turn_to_LL(t[])-n*turn_to_LL(t[]))/(m-n) + 0.5);
//cout << double(m*turn_to_LL(t[4])-n*turn_to_LL(t[3]))/(m-n) << endl;
Time res = turn_to_time(tmp);
printf("%.2d:%.2d:%.2d\n", res.h, res.m, res.s);
}
return ;
}
 

【推公式】UVa 10995 - Educational Journey的更多相关文章

  1. 简单几何(推公式) UVA 11646 Athletics Track

    题目传送门 题意:给了长宽比例,操场一圈400米,问原来长宽的长度 分析:推出公式 /************************************************ * Author ...

  2. HDU 4873 ZCC Loves Intersection(JAVA、大数、推公式)

    在一个D维空间,只有整点,点的每个维度的值是0~n-1 .现每秒生成D条线段,第i条线段与第i维度的轴平行.问D条线段的相交期望. 生成线段[a1,a2]的方法(假设该线段为第i条,即与第i维度的轴平 ...

  3. HDU 4870 Rating(概率、期望、推公式) && ZOJ 3415 Zhou Yu

    其实zoj 3415不是应该叫Yu Zhou吗...碰到ZOJ 3415之后用了第二个参考网址的方法去求通项,然后这次碰到4870不会搞.参考了chanme的,然后重新把周瑜跟排名都反复推导(不是推倒 ...

  4. HDU 5047 推公式+别样输出

    题意:给n个‘M'形,问最多能把平面分成多少区域 解法:推公式 : f(n) = 4n(4n+1)/2 - 9n + 1 = (8n+1)(n-1)+2 前面部分有可能超long long,所以要转化 ...

  5. CCF 201312-4 有趣的数 (数位DP, 状压DP, 组合数学+暴力枚举, 推公式, 矩阵快速幂)

    问题描述 我们把一个数称为有趣的,当且仅当: 1. 它的数字只包含0, 1, 2, 3,且这四个数字都出现过至少一次. 2. 所有的0都出现在所有的1之前,而所有的2都出现在所有的3之前. 3. 最高 ...

  6. bjfu1211 推公式,筛素数

    题目是求fun(n)的值 fun(n)= Gcd(3)+Gcd(4)+…+Gcd(i)+…+Gcd(n).Gcd(n)=gcd(C[n][1],C[n][2],……,C[n][n-1])C[n][k] ...

  7. sgu495:概率dp / 推公式

    概率题..可以dp也可以推公式 抽象出来的题目大意: 有 n个小球,有放回的取m次  问 被取出来过的小球的个数的期望 dp维护两个状态 第 i 次取出的是 没有被取出来过的小球的 概率dp[i] 和 ...

  8. ASC(22)H(大数+推公式)

    High Speed Trains Time Limit: 4000/2000MS (Java/Others)Memory Limit: 128000/64000KB (Java/Others) Su ...

  9. hdu_5810_Balls and Boxes(打表推公式)

    题目链接:hdu_5810_Balls and Boxes 题意: 如题,让你求那个公式的期望 题解: 打表找规律,然后推公式.这项技能必须得学会 #include<cstdio> #in ...

随机推荐

  1. Android View事件传递机制

    ViewGroup dispatchTouchEvent onInterceptTouchEvent onTouch View dispatchTouchEvent onTouch 假设View的层级 ...

  2. ocp 1Z0-047 61-130题解析

    61. Evaluate the following SQL statements that are issued in the given order:CREATE TABLE emp(emp_no ...

  3. Spring MVC BeanNameUrlHandlerMapping example

    In Spring MVC, BeanNameUrlHandlerMapping is the default handler mapping mechanism, which maps URL re ...

  4. ural 1303 Minimal Coverage(贪心)

    链接: http://acm.timus.ru/problem.aspx?space=1&num=1303 按照贪心的思想,每次找到覆盖要求区间左端点时,右端点最大的线段,然后把要求覆盖的区间 ...

  5. 如何将std::string转int,double? (C/C++) (C) (template)

    http://www.cnblogs.com/oomusou/archive/2008/08/01/525647.html http://blog.sina.com.cn/s/blog_a843a88 ...

  6. PHP linux spl_autoload_register区分大小写

    一个PHP脚本用到spl_autoload_register,在WINDOWS下运行正常,但在LINUX就include不了,后来发现WINDOWS大小写不敏感,而在LINUX下区分大小写,WINDO ...

  7. POJ 1979 dfs和bfs两种解法

      fengyun@fengyun-server:~/learn/acm/poj$ cat 1979.cpp #include<cstdio> #include<iostream&g ...

  8. 错误内存【读书笔记】C程序中常见的内存操作有关的典型编程错误

    题记:写这篇博客要主是加深自己对错误内存的认识和总结实现算法时的一些验经和训教,如果有错误请指出,万分感谢. 对C/C++程序员来讲,内存管理是个不小的挑战,绝对值得慎之又慎,否则让由上万行代码构成的 ...

  9. int *(*a[5])(int, char*)

    int* 表示是一个int型指针;(*a[5])(int, char*)中的a[5]表示是一个有5个元素的数组,而(*)(int, char*)则表示指向一个函数的指针,该函数有两个参数,第一个参数为 ...

  10. MySQL 5.7 参数 – log_timestamps

    http://www.ttlsa.com/mysql/mysql-5-7-kengdieparam-log_timestamps/ 官网原话: This variable was added in M ...