题意
有三个人要去拜访神牛。
一开始A在最后面,然后依次是C、M。
现在给出A超过C、M的时间,A到D的时间,C到D的时间、M到D的时间,求C超过M的时间。
思路
第一个时间的给出的唯一作用就是为了当参考的时间。
考虑现在我们在第一个时间点:
A和C重合。
Sam即为Scm
那么
ScmVa−Vm=t2−t1
ScdVa=t3−t1
ScdVc=t4−t1
SmdVm=t5−t1
为了方便,我们可以设
Scd=1⇒Va=1t3−t1,Vc=1t4−t1
然后我们来到第二个时间点,即A和M重合的时候。
因为Va已知,所以
Smd=Va∗(t4−t2)
md的距离知道了,我们就可以得出Vm了。
Vm=Sadt5−t2
然后我们回到第一个时间点。
根据第一条式子,我们可以得出那时候的Scm,然后除一下(vc-vm)再加上t1就行了。因为参考的时间点是t1。
代码
#include <stack>
#include <cstdio>
#include <list>
#include <cassert>
#include <set>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <functional>
#include <cstring>
#include <algorithm>
#include <cctype>
#include <string>
#include <map>
#include <cmath>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/hash_policy.hpp>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define SZ(x) (int)x.size()
#define Lowbit(x) ((x) & (-x))
#define MP(a, b) make_pair(a, b)
#define MS(arr, num) memset(arr, num, sizeof(arr))
#define PB push_back
#define X first
#define Y second
#define ROP freopen("input.txt", "r", stdin);
#define MID(a, b) (a + ((b - a) >> 1))
#define LC rt << 1, l, mid
#define RC rt << 1|1, mid + 1, r
#define LRT rt << 1
#define RRT rt << 1|1
#define FOR(i, a, b) for ((i)=(a); (i) < (b); (i)++)
const double PI = acos(-1.0);
const int INF = 0x3f3f3f3f;
const double eps = 1e-8;
const int MAXN = 1e5+10;
const int MOD = 1e9;
const int dir[][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} };
const int seed = 131;
int cases = 0;
typedef pair<int, int> pii;
int t[10];
char str[100];
void handle_input(int n)
{
int hour, minu, sec;
sscanf(str, "%d:%d:%d", &hour, &minu, &sec);
t[n] = hour*3600 + minu*60 + sec;
}
int main()
{
//ROP;
while (scanf("%s", str))
{
if (str[0] == '-') break;
handle_input(1);
for (int i = 2; i <= 5; i++)
{
scanf("%s", str);
handle_input(i);
}
double va = 1.0/(t[3]-t[1]), vc = 1.0/(t[4]-t[1]);
double vm = va*(t[3]-t[2]) / (t[5]-t[2]);
double res = (t[2]-t[1])*(va-vm) / (vc-vm) + t[1];
int seconds = (int)(res+0.5);
int minute = seconds / 60; seconds %= 60;
int hour = minute / 60; minute %= 60;
hour %= 24;
printf("%02d:%02d:%02d\n", hour, minute, seconds);
}
return 0;
}