【推公式】UVa 10995 - Educational Journey
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, 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.
A passed C and M at time t1 and t2, respectively, and met D at time t3. D 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 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.
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的更多相关文章
- 简单几何(推公式) UVA 11646 Athletics Track
题目传送门 题意:给了长宽比例,操场一圈400米,问原来长宽的长度 分析:推出公式 /************************************************ * Author ...
- HDU 4873 ZCC Loves Intersection(JAVA、大数、推公式)
在一个D维空间,只有整点,点的每个维度的值是0~n-1 .现每秒生成D条线段,第i条线段与第i维度的轴平行.问D条线段的相交期望. 生成线段[a1,a2]的方法(假设该线段为第i条,即与第i维度的轴平 ...
- HDU 4870 Rating(概率、期望、推公式) && ZOJ 3415 Zhou Yu
其实zoj 3415不是应该叫Yu Zhou吗...碰到ZOJ 3415之后用了第二个参考网址的方法去求通项,然后这次碰到4870不会搞.参考了chanme的,然后重新把周瑜跟排名都反复推导(不是推倒 ...
- HDU 5047 推公式+别样输出
题意:给n个‘M'形,问最多能把平面分成多少区域 解法:推公式 : f(n) = 4n(4n+1)/2 - 9n + 1 = (8n+1)(n-1)+2 前面部分有可能超long long,所以要转化 ...
- CCF 201312-4 有趣的数 (数位DP, 状压DP, 组合数学+暴力枚举, 推公式, 矩阵快速幂)
问题描述 我们把一个数称为有趣的,当且仅当: 1. 它的数字只包含0, 1, 2, 3,且这四个数字都出现过至少一次. 2. 所有的0都出现在所有的1之前,而所有的2都出现在所有的3之前. 3. 最高 ...
- 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] ...
- sgu495:概率dp / 推公式
概率题..可以dp也可以推公式 抽象出来的题目大意: 有 n个小球,有放回的取m次 问 被取出来过的小球的个数的期望 dp维护两个状态 第 i 次取出的是 没有被取出来过的小球的 概率dp[i] 和 ...
- ASC(22)H(大数+推公式)
High Speed Trains Time Limit: 4000/2000MS (Java/Others)Memory Limit: 128000/64000KB (Java/Others) Su ...
- hdu_5810_Balls and Boxes(打表推公式)
题目链接:hdu_5810_Balls and Boxes 题意: 如题,让你求那个公式的期望 题解: 打表找规律,然后推公式.这项技能必须得学会 #include<cstdio> #in ...
随机推荐
- 典型LoadRunner脚本
Action() { int rc = 0; int cmp_result = 0; char over_msg[] = "\"真遗憾,好心塞,手慢了一下,已经被人抢走了,再去看看 ...
- MySQL支持Emoji表情
让MySQL支持Emoji表情,涉及无线相关的 MySQL 数据库建议都提前采用 utf8mb4 字符集. utf8mb4和utf8到底有什么区别呢?原来以往的mysql的utf8一个字符最多3字节, ...
- POJ 3369 Meteor Shower (BFS,水题)
题意:给定 n 个炸弹的坐标和爆炸时间,问你能不能逃出去.如果能输出最短时间. 析:其实这个题并不难,只是当时没读懂,后来读懂后,很容易就AC了. 主要思路是这样的,先标记所有的炸弹的位置,和时间,在 ...
- MongoDB学习笔记(一) MongoDB介绍及安装
转自:http://database.51cto.com/art/201103/247882.htm http://baike.baidu.com/link?url=b6B3dVSCnQauCX-Ep ...
- setbuf和freopen
看memcached代码的时候学习了一个api,setbuf,可以设置文件流的缓冲区. #include <stdio.h> void setbuf(FILE *stream ...
- Android中图表AChartEngine学习使用与例子
很多时候项目中我们需要对一些统计数据进行绘制表格,更多直观查看报表分析结果.基本有以下几种方法: 1:可以进行android api进行draw这样的话,效率比较低 2:使用开源绘表引擎,这样效率比 ...
- cdoj 1252 24点游戏 dfs
24点游戏 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/1252 Descr ...
- Codeforces Gym 100286B Blind Walk DFS
Problem B. Blind WalkTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/cont ...
- Oracle 生成随机密码
需求:需要定期更改密码.要求是1.密码位数11位.2.必须包含大小写字母.数字.特殊字符.3.排除一些特殊字符如().@.& oracle数据库中有可已生成随机密码包dbms_random,但 ...
- 4.Maven概念模型,maven的生命周期,Maven坐标,依赖管理(依赖范围,依赖声明),仓库管理,私服概念
1 maven概念模型 2 maven的生命周期,项目构建过程 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdG90b3R1enVvcXVhbg== ...