读懂题后其实就是一道数学题了
hit:
The distance between adjacent centers will be at least 2.0 (so the cylinders do not overlap) and at most 3.4...3.4=1+1+1.4,1.4=sqrt(2);
#include <stdio.h>
#include <math.h>
double num[20][20], numy[20][20];
int n;
void getpoint( double x1, double y1, double x2, double y2 , double & x, double & y )
{
double a, b, c, d, e, f;
a= x2-x1;
b= y2-y1;
c= (x1+x2)/2.0;
d= (y1+y2)/2.0;
e= (y1-y2)/2.0;
f= (x1-x2)/2.0;
y=sqrt( (4-e*e-f*f)*a*a/(a*a+b*b) ) + d;
x= ( b*( d-y )/a )+c;
}
int main()
{
scanf("%d", &n);
for ( int l= 1; l <= n; l++ )
{
int t;
scanf("%d", &t);
int i, j;
for ( i = 0; i < t ; i++ )
{
scanf("%lf", num[t-1]+i);
numy[t-1][i]=1.0;
}
for ( j = t-1; j > 0 ; j-- )
{
for ( i = 0; i < t; i++ )
{
getpoint(num[j][i], numy[j][i], num[j][i+1], numy[j][i+1], num[j-1][i], numy[j-1][i]);
}
}
printf("%d: %.4f %.4f\n", l, num[0][0], numy[0][0]);
}
return 0;
}