【Good Bye 2017 C】 New Year and Curling
【链接】 我是链接,点我呀:)
【题意】
【题解】
枚举前i-1个圆。 哪些圆和它相交。 取圆心纵坐标最大的那个圆就可以了。【代码】
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3;
vector<pair<int,double> >now;
int a[N+10],n,r;
int main(){
#ifdef LOCAL_DEFINE
freopen("rush_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(0),cin.tie(0);
cin >>n >> r;
for (int i = 1;i <= n;i++) cin >> a[i];
for (int i = 1;i <= n;i++){
int len = now.size();
pair<int,double> kk;
kk.second = -1;
for (int j = 0;j < len;j++)
if (now[j].first>=a[i]-2*r && now[j].first<=a[i]+2*r){
double deltax = abs(a[i]-now[j].first);
double r2 = 2*r;
double deltay = sqrt(r2*r2-deltax*deltax);
kk.second = max(kk.second,now[j].second+deltay);
}
if (kk.second<0)
now.push_back(make_pair(a[i],r));
else{
now.push_back(make_pair(a[i],kk.second));
}
}
for (int i = 0;i < (int)now.size();i++){
cout <<fixed<<setprecision(10)<<now[i].second<<' ';
}
return 0;
}