【HDOJ】4932 Miaomiao's Geometry

递归检测。因为dis数组开的不够大,各种wa。写了个数据发生器,果断发现错误,改完就过了。

 #include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; #define MAXN 55 int n;
double a[MAXN], dis[MAXN*];
char visit[MAXN]; // 0: false, 1: left, 2:right bool dfs(int x, double l) {
if (x == n-)
return true;
if (x == ) {
visit[x] = ;
return dfs(x+, l);
}
if (visit[x-] == ) {
if (a[x-]+l <= a[x]) {
visit[x] = ;
if ( dfs(x+, l) )
return true;
} else if (a[x]+l <= a[x+]) {
visit[x] = ;
return dfs(x+, l);
}
return false;
} else {
if (a[x-]+*l <= a[x] || a[x-]+l==a[x]) {
visit[x] = ;
if ( dfs(x+, l) )
return true;
} else if (a[x]+l <= a[x+]) {
visit[x] = ;
return dfs(x+, l);
}
return false;
}
} int main() {
//FILE *fout = fopen("data", "w");
int case_n, m;
int i; scanf("%d", &case_n);
while (case_n--) {
scanf("%d", &n);
for (i=; i<n; ++i)
scanf("%lf", &a[i]);
sort(a, a+n);
for (m=, i=; i<n; ++i) {
dis[m++] = a[i] - a[i-];
dis[m++] = (a[i] - a[i-])/;
}
sort(dis, dis+m);
dis[m] = 0.0f;
for (i=m-; i>=; --i) {
if (dis[i] != dis[i+]) {
memset(visit, , sizeof(visit));
if ( dfs(, dis[i]) )
break;
}
}
printf("%.3lf\n", dis[i]);
//fprintf(fout, "%.3lf\n", dis[i]);
} return ;
}
上一篇:scrapy基本使用(一)


下一篇:apache-php