【推公式】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 ...
随机推荐
- HDU 3072 Intelligence System (强连通分量)
Intelligence System Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- BestCoder Round #65 hdu5591(尼姆博弈)
ZYB's Game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- InnoDB与MyISAM的区别
MyISAM 和 InnoDB 讲解 InnoDB和MyISAM是许多人在使用MySQL时最常用的两个表类型,这两个表类型各有优劣,视具体应用而定.基本的差别为:MyISAM类型不支持事务处理等高级处 ...
- C#中的表达式树简介
表达式树是.NET 3.5之后引入的,它是一个强大灵活的工具(比如用在LINQ中构造动态查询). 先来看看Expression类的API接口: using System.Collections.Obj ...
- Unity3D细节整理:AssetBundle对应的各种格式文件的类型
我们打包AssetBundle后,Unity3D会根据文件的后缀名将文件转换为特定的类型对象存储起来,我们后期获取时需要根据这些类型取出打包的数据,这里记录下不同后缀文件打包后的类型. 文本格式 支持 ...
- TypeScript学习笔记(六):泛型
认识泛型 TypeScript也实现了类型于C#和Java的泛型以实现类型的参数化,我们先看一个需求: function identity(arg: any): any { return arg; } ...
- SAE搭建WordPress教程 免费建WordPress博客站
SAE搭建WordPress教程 免费建WordPress博客站 WordPress是一种使用PHP语言开发的博客平台,用户可以在支持PHP和MySQL数据库的服务器上架设自己的网志.当然,用户也可以 ...
- Windows 下如何设置 只允许固定IP远程访问
通过设置IP安全策略限制固定IP访问 说明: (1)以XP环境为例,步骤:先禁止所有IP,再允许固定IP访问. (2)配置过程中很多步骤图是重复的,一些没价值的图就省略了: (3)光看的话可能中间重复 ...
- Proactor设计模式:单线程高并发
Boost::Asio为同步和异步操作提供了并行支持,异步支持基于前摄器模式,这种模式的优点和缺点可能比只同步或反应器方法要低. 让我们检查一下Boost::Asio是如何实现前摄器模式的,没有引用基 ...
- 一个简洁通用的调用DLL函数的帮助类
本次介绍一种调用dll函数的通用简洁的方法,消除了原来调用方式的重复与繁琐,使得我们调用dll函数的方式更加方便简洁.用过dll的人会发现c++中调用dll中的函数有点繁琐,调用过程是这样的:在加载d ...