题目链接:
解题思路:
飞机在飞,由于人为规定的时区导致好像时间变慢或者快了(实际上没有)。这里很像我们高中物理学的运动学知识,我们可以假设一个场景——船在不平静水面行驶,船从一个点出发行驶了s路程后返回原点(期间船速不变),然后告诉我们来回整个过程回到原点的时间是t,问船在静水中行驶s路程需要多长时间。我们可以以水为参考系,那么显然这个时间为 t/2。
时差由东向西为减,由西向东为加,由于飞机往返飞行时间相同,所以可以列个飞机往返时间的等式 t 2 − t 1 − t d = t 4 − t 3 + t d t2 - t1 - td = t4 - t3 + td t2−t1−td=t4−t3+td , 可以得到:时差 t d = ( ( t 2 − t 1 ) + ( t 4 − t 3 ) ) / 2 td = ((t2 - t1) + (t4 - t3)) / 2 td=((t2−t1)+(t4−t3))/2
PS:输入也是一个坑点
#include<bits/stdc++.h>
#define x first
#define y second
#define mem1(h) memset(h,-1,sizeof h)
#define mem0(h) memset(h,0,sizeof h)
#define mcp(a,b) memcpy(a,b,sizeof b)
using namespace std;
typedef long long LL;
typedef unsigned long long ull;
typedef pair<int,int>PII;
typedef pair<double,double>PDD;
namespace IO{
inline LL read(){
LL o=0,f=1;char c=getchar();
while(c<0||c>9){
if(c==-)f=-1;c=getchar();}
while(c>=0&&c<=9){
o=o*10+c-0;c=getchar();}
return o*f;
}
}using namespace IO;
//#############以上是自定义技巧(可忽略)##########
const int N=1e6+7,M=2e5+7,INF=0x3f3f3f3f,mod=1e8+7,P=131;
int n;
int get_seconds(int h,int m,int s){
return h*3600+m*60+s;
}
int get_time(){
string line;
getline(cin,line);
if(line.back()!=))line+=" (+0)";//如果时间没有看跨天,我们默认给他补上0,方便后面计算
int h1,m1,s1,h2,m2,s2,d;
sscanf(line.c_str(),"%d:%d:%d %d:%d:%d (+%d)",&h1,&m1,&s1,&h2,&m2,&s2,&d);
return get_seconds(h2,m2,s2)-get_seconds(h1,m1,s1)+d*24*3600;
}
int main(){
cin>>n;
string line;
getline(cin,line);//抵消掉第一行的回车
while(n--){
int d=(get_time()+get_time())/2;
printf("%02d:%02d:%02d
",d/3600,d%3600/60,d%60);
}
return 0;
}