题目链接:CodeForces 908C【New Year and Curling】
思路
模拟,考虑到两个圆盘可能出现y值相同且相接的情况,所以在判断当前圆盘的y值时循环的范围从在前圆盘的x值左右浮动2r,依次遍历这个范围内的数组y(存储的是当前已经移动了圆盘中的横坐标为i的圆盘的最大的y值),然后可以通过三角形的边长计算出dis,依次枚举每个x取得到的y中的最大值。
代码
#include <iomanip>
#include <iostream>
#include <math.h>
using namespace std;
#define ll long long
const int N = 2e3 + 10;
double l, r;
int x[N];
double y[N], mark[N];
int n;
void solve() {
cin >> n >> r;
for (int i = 1; i <= n; i++) {
cin >> x[i];
double relay = 0;
for (int j = max(-r * 2, (double)-x[i] + 1); j <= (int)r * 2; j++) {
double dis = 4 * r * r - j * j;
if (j == 0 && y[x[i]] == 0)
dis = r;
else if (j == 0)
dis = 2 * r + y[x[i]];
else if (y[j + x[i]] == 0)
dis = r;
else
dis = sqrt(dis) + y[j + x[i]];
relay = max(relay, dis);
}
y[x[i]] = relay;
mark[i] = relay;
}
cout << setprecision(12);
for (int i = 1; i <= n; i++) {
cout << mark[i] << " ";
}
}
int main() {
int t = 1;
while (t--) {
solve();
}
return 0;
}
标签:Curling,int,double,CodeForces,圆盘,New,include,908C
From: https://www.cnblogs.com/againss/p/18336040