mirror of
https://github.com/Kiritow/OJ-Problems-Source.git
synced 2024-03-22 13:11:29 +08:00
Create 4932_lyhvoyage.cpp
From http://blog.csdn.net/lyhvoyage/article/details/38486961
This commit is contained in:
parent
486660463d
commit
47442f267e
57
HDOJ/4932_lyhvoyage.cpp
Normal file
57
HDOJ/4932_lyhvoyage.cpp
Normal file
|
@ -0,0 +1,57 @@
|
|||
#include<cstdio>
|
||||
#include<cstring>
|
||||
#include<algorithm>
|
||||
using namespace std;
|
||||
int main()
|
||||
{
|
||||
double b[120], c[60];
|
||||
int flag[60];
|
||||
int n, i, j, T;
|
||||
scanf("%d",&T);
|
||||
while(T--)
|
||||
{
|
||||
scanf("%d",&n);
|
||||
for(i = 0; i < n; i++)
|
||||
scanf("%lf",&c[i]);
|
||||
sort(c, c+n);
|
||||
int m = 0;
|
||||
for(i = 1; i < n; i++)
|
||||
{
|
||||
b[m++] = c[i] - c[i-1];
|
||||
b[m++] = (c[i] - c[i-1]) / 2;
|
||||
}
|
||||
sort(b, b+m);
|
||||
double ans;
|
||||
for(i = m - 1; i >= 0; i--)
|
||||
{
|
||||
memset(flag, 0, sizeof(flag));
|
||||
flag[0] = 1;
|
||||
double tmp = b[i];
|
||||
for(j = 1; j < n - 1; j++)
|
||||
{
|
||||
if(c[j] - tmp < c[j-1] && c[j] + tmp > c[j+1]) //往左往右都不行
|
||||
break;
|
||||
if(c[j] - tmp >= c[j-1])
|
||||
{
|
||||
if(flag[j-1] == 2) // 前一个往右
|
||||
{
|
||||
if(c[j] - c[j-1] == tmp) flag[j] = 1; //两个点作为线段的两个端点
|
||||
else if(c[j] - c[j-1] >= 2 * tmp) flag[j] = 1; //一个往左,一个往右
|
||||
else if(c[j] + tmp <= c[j+1]) flag[j] = 2; //只能往右
|
||||
else break;
|
||||
}
|
||||
else flag[j] = 1;
|
||||
}
|
||||
else if(c[j] + tmp <= c[j+1])
|
||||
flag[j] = 2;
|
||||
}
|
||||
if(j == n - 1)
|
||||
{
|
||||
ans = tmp;
|
||||
break;
|
||||
}
|
||||
}
|
||||
printf("%.3lf\n", double(ans));
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user