[蓝桥杯][2018年第九届真题]航班时间

题目链接:航班时间



解题思路:

飞机在飞,由于人为规定的时区导致好像时间变慢或者快了(实际上没有)。这里很像我们高中物理学的运动学知识,我们可以假设一个场景——船在不平静水面行驶,船从一个点出发行驶了s路程后返回原点(期间船速不变),然后告诉我们来回整个过程回到原点的时间是t,问船在静水中行驶s路程需要多长时间。我们可以以水为参考系,那么显然这个时间为 t/2。

时差由东向西为减,由西向东为加,由于飞机往返飞行时间相同,所以可以列个飞机往返时间的等式 t 2 − t 1 − t d = t 4 − t 3 + t d t2 - t1 - td = t4 - t3 + td t2t1td=t4t3+td , 可以得到:时差 t d = ( ( t 2 − t 1 ) + ( t 4 − t 3 ) ) / 2 td = ((t2 - t1) + (t4 - t3)) / 2 td=((t2t1)+(t4t3))/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\n",d/3600,d%3600/60,d%60);
	}
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值