【推公式】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 ...
随机推荐
- POJ 3026 Borg Maze (最小生成树)
Borg Maze 题目链接: http://acm.hust.edu.cn/vjudge/contest/124434#problem/I Description The Borg is an im ...
- android使用mount挂载/system/app为读写权限,删除或替换系统应用
注意:以下代码中#开头的则为需要执行的shell命令,其他的为打印的结果.#代表需要使用ROOT权限(su)执行,所以想要修改您android手机某个目录挂载为读写,首先需要有ROOT权限! 先要得到 ...
- linux使用getopt解析参数
getopt是linux下解析命令行参数的api.以linux内核代码的一个例子来说明: static void cmdline(int argc, char *argv[]){ int o ...
- pygame “音乐盒”---- 播放一首歌& 点击对话框后背景以及对话框大小改变
有时,你用pygame写的游戏也许需要播放一些背景音乐,该怎么做呢,直接上代码: 下面的代码,有关于: 1>设置对话框图标.大小.标题 2>播放音乐 3>设置背景图片,以及获取背景图 ...
- CSS3教程:Transform的perspective属性设置
1 2 <div id="animateTest" style="-webkit-transform: perspective(400px) rotateY(4 ...
- C语言根据日期取其位于一年中的第几天
#include <iostream> #include <stdlib.h> using namespace std; bool isLeapYear( int iYear ...
- Install eclipse groovy plugin
http://dist.springsource.org/release/GRECLIPSE/e4.4/
- PHP+MySQL多语句执行<转自wooyun>
发起这个帖子,估计就很多人看到题目就表示不屑了.一直以来PHP+MySQL环境下,无论是写程序或者是注入攻击,是无法多语句执行的,这么广为人知的常识,没理由会有人不知道.可权威就是用来被挑战的,常识也 ...
- [Oracle] Group By 语句的扩展 - Rollup、Cube和Grouping Sets
常常写SQL语句的人应该知道Group by语句的主要使用方法是进行分类汇总,以下是一种它最常见的使用方法(依据部门.职位分别统计业绩): SELECT a.dname,b.job,SUM(b.sal ...
- [Ramada] Build a Functional Pipeline with Ramda.js
We'll learn how to take advantage of Ramda's automatic function currying and data-last argument orde ...