Miaomiao's Geometry
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 379 Accepted Submission(s): 93
Problem Description
There are N point on X-axis . Miaomiao would like to cover them ALL by using segments with same length.
There are 2 limits:
1.A point is convered if there is a segments T , the point is the left end or the right end of T.
2.The length of the intersection of any two segments equals zero.
For example , point 2 is convered by [2 , 4] and not convered by [1 , 3]. [1 , 2] and [2 , 3] are legal segments , [1 , 2] and [3 , 4] are legal segments , but [1 , 3] and [2 , 4] are not (the length of intersection doesn't equals zero), [1 , 3] and [3 , 4] are not(not the same length).
Miaomiao wants to maximum the length of segements , please tell her the maximum length of segments.
For your information , the point can't coincidently at the same position.
There are 2 limits:
1.A point is convered if there is a segments T , the point is the left end or the right end of T.
2.The length of the intersection of any two segments equals zero.
For example , point 2 is convered by [2 , 4] and not convered by [1 , 3]. [1 , 2] and [2 , 3] are legal segments , [1 , 2] and [3 , 4] are legal segments , but [1 , 3] and [2 , 4] are not (the length of intersection doesn't equals zero), [1 , 3] and [3 , 4] are not(not the same length).
Miaomiao wants to maximum the length of segements , please tell her the maximum length of segments.
For your information , the point can't coincidently at the same position.
Input
There are several test cases.
There is a number T ( T <= 50 ) on the first line which shows the number of test cases.
For each test cases , there is a number N ( 3 <= N <= 50 ) on the first line.
On the second line , there are N integers Ai (-1e9 <= Ai <= 1e9) shows the position of each point.
There is a number T ( T <= 50 ) on the first line which shows the number of test cases.
For each test cases , there is a number N ( 3 <= N <= 50 ) on the first line.
On the second line , there are N integers Ai (-1e9 <= Ai <= 1e9) shows the position of each point.
Output
For each test cases , output a real number shows the answser. Please output three digit after the decimal point.
Sample Input
3 3 1 2 3 3 1 2 4 4 1 9 100 10
Sample Output
1.000 2.000 8.000HintFor the first sample , a legal answer is [1,2] [2,3] so the length is 1. For the second sample , a legal answer is [-1,1] [2,4] so the answer is 2. For the thired sample , a legal answer is [-7,1] , [1,9] , [10,18] , [100,108] so the answer is 8.
Source
题目意思:
给你n个位置,你要用等长度的区间线段去覆盖他们,而且只能用端点去覆盖,不能出现位置点在区间线段内的情况。问最大长度是多少,位置点的范围是-1e9~1e9。
分析:由于线段条数只有50条,那么对于排序后的位置点从间距最大的长度开始暴力检查,但是注意,取一半的情况1 2 5 6 8这样的。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#define rt return
#define sf scanf
#define pf printf
#define si(n) sf("%d",&n)
#define pi(n) pf("%d",n)
#define REP0(i,n) for(int i=0;i<(n);i++)
#define REP1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,s,n) for(int i=s;i<=(n);i++)
#define db double
#define pb push_back
#define LL long long
#define INF 0x3fffffff
#define eps 1e-8
#define PI acos(-1)
#define maxn 55
using namespace std;
int n;
double pos[maxn],pp[maxn];
double len[maxn*2];
int main(){
#ifdef ACBang
freopen("in.txt","r",stdin);
#endif
int T;sf("%d",&T);
while(T--){
sf("%d",&n);
REP0(i,n)
sf("%lf",&pos[i]);
sort(pos,pos+n);
for(int i=0;i<n;i++)
pp[i]=pos[i];
int k=0;
REP0(i,n-1){
len[k++]=abs(pos[i+1]-pos[i]);
len[k++]=len[k-1]*0.5;
}
// REP0(i,k)cout<<len[i]<<" ";cout<<endl;
sort(len,len+k);
int l=unique(len,len+k)-len;
for(int i=l-1;i>=0;i--){
for(int t=0;t<n;t++)
pos[t]=pp[t];
bool tmp=true;
for(int j=1;j<n-1;j++){
if(pos[j-1]<=pos[j]-len[i])
continue;
if(pos[j]+len[i]<pos[j+1]){
pos[j]=pos[j]+len[i];
continue;
}
if(pos[j]+len[i]==pos[j+1]){
continue;
}
tmp=false;
break;
}
if(tmp==true){
pf("%.3lf\n",len[i]);
break;
}
}
}
rt 0;
}