const double eps = 1e-6;
const int maxn = 1100;
inline int dcmp(double x)
{
if (fabs(x) < eps) return 0;
return x < 0 ? -1 : 1;
}
struct Point
{
double x, y;
Point(double x = 0, double y = 0) : x(x), y(y) {}
};
struct Circle
{
Point p;
double r;
} ipt[maxn];
double x[maxn];
int pre[maxn];
bool vis[maxn];
int ans = 0;
void dfs(int u)
{
ans--;
vis[u] = true;
if (pre[u] == u)
return;
if (!vis[pre[u]])
dfs(pre[u]);
}
int main()
{
//freopen("0.txt", "r", stdin);
int n;
while (~RI(n))
{
ans = n;
FE(i, 1, n)
{
scanf("%lf", &ipt[i].r);
ipt[i].p.y = ipt[i].r;
pre[i] = i;
vis[i] = false;
}
ipt[1].p.x = ipt[1].r;
double Max = ipt[1].p.x + ipt[1].r;
int id = 1;
FE(i, 2, n)
{
double xmax = ipt[i].r;
FE(j, 1, i - 1)
{
x[j] = 2 * sqrt(ipt[i].r * ipt[j].r) + ipt[j].p.x;
if (dcmp(xmax - x[j]) < 0)
xmax = x[j];
}
FE(j, 1, i - 1)
{
if (dcmp(x[j] - xmax) == 0)
{
pre[i] = j;
break;
}
}
ipt[i].p.x = xmax;
if (dcmp(ipt[i].p.x + ipt[i].r - Max) > 0)
{
Max = ipt[i].p.x + ipt[i].r;
id = i;
}
}
dfs(id);
WI(ans);
FE(i, 1, n)
{
if (!vis[i])
WI(i);
}
}
return 0;
}原文:http://blog.csdn.net/wty__/article/details/38590815