Problem C:Circles

链接:https://ac.nowcoder.com/acm/contest/18458/C
来源:牛客网
 

时间限制:C/C++ 8秒,其他语言16秒
空间限制:C/C++ 1048576K,其他语言2097152K
Special Judge, 64bit IO Format: %lld

题目描述

There are n magical circles on a plane. They are centered at (x1, y1),(x2, y2), . . . ,(xn, yn), respectively. In the beginning, the radius of each circle is 0, and the radii of all magical circles will grow at the same rate. When an magical circle touches another, then it stops growing. Write a program to calculate the total area of all magical circles at the end of growing. 

输入描述:

The first line contains an integer n to indicate the number of magical circles. The i-th of thefollowing n lines contains two space-separated integers xi and yi indicating that the i-th magicalcircle is centered at (xi , yi).

输出描述:

Output the total area of the circles. 

示例1

输入

复制

4
0 0
1 0
1 1
0 1

输出

复制

3.14159265359

示例2

输入

复制

3
0 0
0 1
2 0

输出

复制

8.639379797371932

备注:

 

• 2 ≤ n ≤ 2000 

• xi, yi ∈ [−109, 109] for i ∈ {1, 2, . . . , n}.

• All (xi , yi)’s are disinct points. 

• A relative error of 10−6 is acceptable.

#include<bits/stdc++.h>
using namespace std;
int n, v[2345], cnt;
double x[2345], y[2345], r[2345], ans, d[2345][2345];
priority_queue<pair<double, int>>pq;
double dis(int i, int j)
{
	return hypot(x[i]-x[j], y[i]-y[j]);
}
int main()
{
	cin >> n;
	for(int i = 0; i < n; i++)
	{
		cin >> x[i] >> y[i];
		r[i] = 9e9;
	}
	for(int i = 0; i < n; i++)
		for(int j = i+1; j < n; j++)
		{
			d[i][j] = d[j][i] = dis(i, j);
			pq.push({-d[i][j]/2, i*3000+j});
		}
	while(cnt < n)
	{
		int i = pq.top().second / 3000, j = pq.top().second % 3000;
		pq.pop();
		if(!v[i] && !v[j])
		{
			r[i] = r[j] = d[i][j] / 2;
			ans += 2 * r[i] * r[i];
			v[i] = v[j] = 1;
			cnt += 2;
		}
		else if(!v[i] || !v[j])
		{
			if(v[j])
				swap(i, j);
 			r[j] = d[i][j] - r[i];
 			if(-r[j] < pq.top().first)
 				pq.push({-r[j], i*3000+j});
 			else
 			{
 				v[j] = 1;
 				ans += r[j] * r[j];
 				cnt++;
			}
		}
	}
	printf("%.8f\n", acos(-1)*ans);
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

郭晋龙

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值