当前位置:网站首页>2020 ICPC Asia Taiwan Online Programming Contest C Circles
2020 ICPC Asia Taiwan Online Programming Contest C Circles
2022-06-13 10:57:00 【重生之我会拧瓶盖】
这道题真是忽略了过程就会错,以后再也不一有点思路直接写了。
题目链接++++++++++++++++++++++++
&&&&& 题意大体是刚开始给你n个圆心,游戏开始后每个圆的半径开始以相同的速度增长,当一个圆碰到另一个圆时圆停止增长。这样的话,随着圆的增长其他圆的半径也会被限制(这是动态变化的,肯定最小的两个圆先停止增长,然后其他圆心半径变化,每次需找最小值,可以用优先队列),并不是找到距离每个圆心最近的那个圆心就是停止生长的位置,
题目如下
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.
输入
复制
3
0 0
0 1
2 0
输出
复制
8.639379797371932
输入
复制
4
0 0
1 0
1 1
0 1
输出
复制
3.14159265359
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 2010;
const ll MOD = 1000000007;
const double EPS = 1e-8;
const double pi = acos(-1.0);
struct Node
{
double dis;
int a, b;
bool operator < (const Node &x) const
{
return dis > x.dis;
}
};
priority_queue<Node> Q;
int v[MAXN];
double px[MAXN], py[MAXN], ans[MAXN];
inline double getdis(int a, int b)
{
double X = abs(px[a] - px[b]);
double Y = abs(py[a] - py[b]);
return sqrt(X * X + Y * Y);
}
int main()
{
int n; scanf("%d", &n);
for(int i = 1; i <= n; ++i)
scanf("%lf %lf", &px[i], &py[i]);
for(int i = 1; i <= n; ++i)
for(int j = i + 1; j <= n; ++j)
Q.push((Node){
getdis(i, j) / 2.0, i, j});
while(!Q.empty())
{
Node x = Q.top(); Q.pop();
if(v[x.a] && v[x.b]) continue;
else if(!v[x.a] && !v[x.b])
{
v[x.a] = v[x.b] = 1;
ans[x.a] = ans[x.b] = x.dis;
for(int i = 1; i <= n; ++i)
{
if(!v[i]) Q.push((Node){
getdis(x.a, i) - x.dis, x.a, i});
if(!v[i]) Q.push((Node){
getdis(x.b, i) - x.dis, x.b, i});
}
}
else
{
if(v[x.a]) swap(x.a, x.b);
if(abs(x.dis + ans[x.b] - getdis(x.a, x.b)) < EPS)
{
v[x.a] = 1, ans[x.a] = x.dis;
for(int i = 1; i <= n; ++i)
if(!v[i]) Q.push((Node){
getdis(x.a, i) - x.dis, x.a, i});
}
}
}
double sum = 0;
for(int i = 1; i <= n; ++i)
sum += ans[i] * ans[i] * pi;
printf("%.15f\n", sum);
return 0;
}
这道题又给我了一种新的思路,牛逼!!!!!!!!!
边栏推荐
- Understanding RPC and rest
- Install Kubernetes 1.24
- Vivo large scale kubernetes cluster automation operation and maintenance practice
- JGR-A | 南京大学黄安宁团队揭示高原湖泊山地影响极端降水的动力-热力机制
- [tool chain series] Notepad++
- As a tester, these basic knowledge are essential
- 5.5 clock screensaver
- On the exploitation of a horizontal ultra vires vulnerability
- 记几次略有意思的 XSS 漏洞发现
- To vent their dissatisfaction with their superiors, Baidu post-95 programmers were sentenced to 9 months for deleting the database
猜你喜欢
QTcpServer. QTcpSocket. Differences between qudpsockets
Matplotlib 学习笔记
Pagoda add a website: PHP project
电解电容、钽电容、普通电容
Database learning notes (Chapter 15)
【20220526】UE5.0.2 release d11782b
网传互联网公司加班表,排名第一的没有悬念!
On the exploitation of a horizontal ultra vires vulnerability
What is 400g Ethernet?
MySQL到底怎么优化?
随机推荐
Deploy vscode on kubernetes cluster
Necessary for Architects: system capacity status checklist
Database learning notes (Chapter 16)
SSM integration preliminary details
Private computing fat core concepts and stand-alone deployment
On the exploitation of a horizontal ultra vires vulnerability
2022 tailings recurrent training question bank and simulated examination
QTcpServer. QTcpSocket. Differences between qudpsockets
Pagoda access changed from IP to domain name
Understanding RPC and rest
China SaaS industry panorama
【20220526】UE5.0.2 release d11782b
Necessary for Architects: system capacity status checklist
About instruction set bits and instruction architecture bits
Multithreading starts from the lockless queue of UE4 (thread safe)
文件夹数据同步工具Sync Folders Pro
低代码开发一个基础模块
Spark source code (I) how spark submit submits jars and configuration parameters to spark server
宝塔添加一个网站:PHP项目
实战模拟│企业微信机器人实时报错预警