【推公式】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 ...
随机推荐
- BestCoder Round #71 (div.2) (hdu 5620 菲波那切数列变形)
KK's Steel Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- WinAPI: FindWindow、FindWindowEx - 查找窗口
FindWindow( lpClassName, {窗口的类名} lpWindowName: PChar {窗口的标题} ): HWND; {返回窗口的 ...
- angular 管理后台
http://blog.csdn.net/iamnieo/article/details/50474399
- javabean总结
一. javabean 是什么? Bean的中文含义是“豆子”,顾名思义,JavaBean是指一段特殊的Java类, 就是有默然构造方法,只有get,set的方法的java类的对象. 专业点解释是: ...
- "file:///" file 协议
[问题] 在WLW中拖入本地图片文件,然后调试过程中,选中对应图片,看到获得的对应的html源码中,图片地址是这样的: href="file:///C:/Users/CLi/AppData/ ...
- Invoke-Express 执行多个批处理命令的函数
function Mult_ping ($ips) { # $cmdline = "PIng" foreach ($ip in $ips) { $cmdline = "p ...
- 手机调用系统的拍照和裁剪功能,假设界面有输入框EditText,在一些手机会出现点击EditText会弹出输入法,却不能输入的情况。
1. 拍照裁剪后 点击EditText会弹出输入法,却不能输入.可是点击点一EdtiText就能够输入了,所以我就写了一个看不见的EdtiText,切换焦点,这样就攻克了这个奇怪的这问题,应该是and ...
- CN今日凌晨出现全部瘫痪的故障,持续近6个小时
今日凌晨1点左右,所有cn后缀的网站出现无法访问的情况,原因来自于所有的cn域名均无法解析.据国内知名DNS解析商DNSLA称,故障源自CN所使用的根域名授权服务器瘫痪所致,故障一直持续到今天早上7点 ...
- setuptools的使用
1.什么是setuptools setuptoolssetuptools是 Python Enterprise Application Kit(PEAK)的一个副项目,是Python distutil ...
- Java中for循环以及循环中标签
1.第一种,通过迭代的方式 File[] listFiles = file.listFiles(); for (Iterator iterator = files.iterator(); iterat ...