标签:des style blog http color java os io
3 3 1 2 3 3 1 2 4 4 1 9 100 10
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.
#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; }
hdu 4932 Miaomiao's Geometry(暴力枚举),布布扣,bubuko.com
hdu 4932 Miaomiao's Geometry(暴力枚举)
标签:des style blog http color java os io
原文地址:http://blog.csdn.net/lyhvoyage/article/details/38486961