Solution - Stacking Cylinders
Link。
有一个向量旋转做法,但是我不会。
Note: To help you check your work, the x-coordinate of the center of the top cylinder should be the average of the x-coordinates of the leftmost and rightmost bottom cylinders.
算是一个提示,其实较为显然,这样放在两个横坐标为 \(x_1\) 和 \(x_2\) 的圆之间的圆的横坐标就是 \(\dfrac{x_1 + x_2}{2}\)。
那么纵坐标呢?好像现行题解写的不是很清楚。
观察图片,可知放在两个横坐标为 \(x_1\) 和 \(x_2\) 的圆之间的圆与这两个圆中任意一个的圆心距离都为 \(2r = 2\)。又知道横坐标为 \(\dfrac{x_1 + x_2}{2}\),那么距离就是 \(x_2 - \dfrac{x_1 + x_2}{2} = \dfrac{x_2 - x_1}{2}\)(不妨 \(x_1 < x_2\)),然后纵坐标就勾股一下,\(y ^ 2 + (\dfrac{x_2 - x_1}{2}) ^ 2 = 2 ^ 2\),解得 \(y = \sqrt{4 - (\dfrac{x_2 - x_1}{2}) ^ 2}\),累加即可,因为题目做了一个非常 666 的保证就是 cylinders at level \(k\) will never touch cylinders at level \(k - 2\),相当于每次都是分层计算的,然后因为纵坐标是从 \(1\) 开始的所以最后加上 \(1\) 即可。
namespace liuzimingc {
const int N = 1e6 + 5;
#define endl '\n'
int n;
double x[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
while (cin >> n && n) {
for (int i = 1; i <= n; i++) cin >> x[i];
sort(x + 1, x + 1 + n);
double sum = 1;
for (int i = 1; i < n; i++)
sum += sqrt(4 - pow((x[i + 1] - x[i]) / 2, 2));
cout << fixed << setprecision(4) << (x[1] + x[n]) / 2 << " " << sum << endl;
}
return 0;
}
} // namespace liuzimingc
Posted by liuzimingc