B. Meeting on the Line cf#823 (div.2)

Problem - B - Codeforces

 

题目大意: 有n个人,每个人有自己的要穿衣服的时间,然后让你求一个地点x,使最晚到达这个地点的人的时间最短。

思路:首先每个人的时间如果为0时,那么这个地点肯定是最大值和最小值的和的一半(艹一开始没想到),但是因为现在有穿衣服的时间,那么在所有人穿衣服的这段时间里面,每个人都会尽可能的往里面走使整个区间缩小,然后直到所有人都穿好衣服,此时区间的最大值和最小值的和也就是我当前的位置。

那么我们就可以在最长的这个穿衣服的人的时间里面,每个人去缩短这个区间的最大值和最小值(用最长的时间-最短时间就是我可以走的时间),最后区间的最大值和最小值加起来除以二就好了。

/**
*  ┏┓   ┏┓+ +
* ┏┛┻━━━┛┻┓ + +
* ┃       ┃
* ┃   ━   ┃ ++ + + +
*  ████━████+
*  ◥██◤ ◥██◤ +
* ┃   ┻   ┃
* ┃       ┃ + +
* ┗━┓   ┏━┛
*   ┃   ┃ + + + +Code is far away from  
*   ┃   ┃ + bug with the animal protecting
*   ┃    ┗━━━┓ 神兽保佑,代码无bug 
*   ┃  	    ┣┓
*    ┃        ┏┛
*     ┗┓┓┏━┳┓┏┛ + + + +
*    ┃┫┫ ┃┫┫
*    ┗┻┛ ┗┻┛+ + + +
*/

#include<cstdio>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include<vector>
#include<queue>
#include<map>
#define sc_int(x) scanf("%d", &x)
#define sc_ll(x) scanf("%lld", &x)
#define pr_ll(x) printf("%lld", x)
#define pr_ll_n(x) printf("%lld\n", x)
#define pr_int_n(x) printf("%d\n", x)
#define ll long long 
using namespace std;

const int N=1000000+100;
int n ,m,h;
ll s[N],ss[N];


int main()
{
	int t;
	sc_int(t);
	while(t--)
	{
		ll Maxn=0;
		sc_int(n);
		for(int i=1;i<=n;i++)sc_int(s[i]);
		for(int i =1;i<=n;i++)
		{
			sc_int(ss[i]);
			Maxn=max(ss[i],Maxn);
		}
		
		ll MAX=0x3f3f3f3f,MIN=0;
		for(int i =1;i<=n;i++)
		{
			MIN=max(MIN,s[i]-(Maxn-ss[i]));
			MAX=min(MAX,s[i]+(Maxn-ss[i]));
		}
		printf("%.7lf\n",(MAX+MIN)/2.0);

	}
	return 0;
}

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值