# 【bzoj1043】[HAOI2008]下落的圆盘 计算几何

2
1 0 0
1 1 0

10.472

#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define N 1010
#define squ(x) ((x) * (x))
using namespace std;
const double pi = acos(-1);
struct data
{
double pl , pr;
bool operator<(const data &a)const {return pl < a.pl;}
}a[N << 1];
double x[N] , y[N] , r[N];
int tot;
int main()
{
int n , i , j;
double afa , beta , d , last , ans = 0;
scanf("%d" , &n);
for(i = 1 ; i <= n ; i ++ ) scanf("%lf%lf%lf" , &r[i] , &x[i] , &y[i]);
for(i = 1 ; i <= n ; i ++ )
{
ans += 2 * pi * r[i];
tot = 0;
for(j = i + 1 ; j <= n ; j ++ )
{
tot ++ , d = squ(x[i] - x[j]) + squ(y[i] - y[j]);
if(squ(r[i] + r[j]) <= d) a[tot].pl = a[tot].pr = 0;
else if(squ(r[i] - r[j]) >= d)
{
if(r[i] > r[j]) a[tot].pl = a[tot].pr = 0;
else a[tot].pl = 0 , a[tot].pr = 2 * pi;
}
else
{
afa = acos((r[i] * r[i] + d - r[j] * r[j]) / (2 * r[i] * sqrt(d)));
beta = atan2(y[j] - y[i] , x[j] - x[i]);
if(beta < 0) beta += 2 * pi;
a[tot].pl = beta - afa , a[tot].pr = beta + afa;
if(a[tot].pl < 0) tot ++ , a[tot].pl = a[tot - 1].pl + 2 * pi , a[tot - 1].pl = 0 , a[tot].pr = 2 * pi;
else if(a[tot].pr > 2 * pi) tot ++ , a[tot].pr = a[tot - 1].pr - 2 * pi , a[tot - 1].pr = 2 * pi , a[tot].pl = 0;
}
}
sort(a + 1 , a + tot + 1);
last = -1;
for(j = 1 ; j <= tot ; j ++ )
{
if(a[j].pr <= last) continue;
if(a[j].pl > last) ans -= (a[j].pr - a[j].pl) * r[i];
else ans -= (a[j].pr - last) * r[i];
last = a[j].pr;
}
}
printf("%.3lf\n" , ans);
return 0;
}


posted @ 2017-08-14 08:56  GXZlegend  阅读(372)  评论(0编辑  收藏  举报