HDU - 3561:How many times
2017-08-10 09:42
239 查看
How many times
HDU- 3561
There are N circles on the plane. Dumbear wants to find a region which is covered by as many circles as possible. But Dumbear is very dumb, so he turns to momodi for help. But momodi is very busy. Can you help him find out the maximum
times that a region can be covered? Notice that a point on a circle’s boundary is considered to be covered by this circle.
InputThere are several test cases in the input.
For each case, the first line contains an integer N (1≤ N ≤ 100) denotes the number of circles.
For the next N lines, each line contains three integers X, Y, R denotes a circle whose center is (X, Y) (-10000 ≤ X, Y ≤ 10000) and radius is R (0 < R ≤ 5000).
The input terminates by end of file marker.
OutputFor each test case, output a single line contains only a number denotes the maximum times that a region can be covered.
Sample Input
3 0 0 1 1 0 1 2 0 1
Sample Output
3
思路:找出一个被圆覆盖最多次的点,那么这个点要是圆心,要么就是圆的交点。枚举所有圆两两相交的交点和所有的圆的圆心。
#include<bits/stdc++.h>
using namespace std;
struct Point
{
double x,y,r;
}node[101];
int n;
vector<struct Point>p;
double dis(const Point& x,const Point& y){return sqrt((x.x-y.x)*(x.x-y.x)+(x.y-y.y)*(x.y-y.y));}
int check(Point x)
{
int sum=0;
for(int i=0;i<n;i++)
{
if(dis(x,node[i])<=node[i].r)sum++;
}
return sum;
}
int main()
{
while(cin>>n)
{
p.clear();
node
.x=node
.y=node
.r=0;
for(int i=0;i<n;i++)cin>>node[i].x>>node[i].y>>node[i].r;
for(int i=0;i<n;i++)
{
p.push_back(node[i]);
for(int j=i+1;j<n;j++)
{
if(dis(node[i],node[j])>node[i].r+node[j].r)continue;
//联立方程组求出两圆的交点
double a=2*node[j].x-2*node[i].x;
double b=2*node[j].y-2*node[i].y;
double c=dis(node[i],node
)*dis(node[i],node
)-dis(node[j],node
)*dis(node[j],node
)+node[j].r*node[j].r-node[i].r*node[i].r;
double y1,y2,x1,x2;
if(b!=0)
{
double A=a*a/(b*b)+1;
double B=2*a*node[i].y/b+2*a*c/(b*b)-2*node[i].x;
double C=dis(node[i],node
)*dis(node[i],node
)+c*c/(b*b)-node[i].r*node[i].r+2*node[i].y*c/b;
double D=B*B-4*A*C;
x1=(-B-sqrt(D))/(2*A); y1=(a*x1+c)/(-b);
x2=(-B+sqrt(D))/(2*A); y2=(a*x2+c)/(-b);
}
else if(a!=0)
{
double A=b*b/(a*a)+1;
double B=b*2*node[i].x/a+2*b*c/(a*a)-2*node[i].y;
double C=dis(node[i],node
)*dis(node[i],node
)-node[i].r*node[i].r+2*node[i].x*c/a+c*c/(a*a);
double D=B*B-4*A*C;
y1=(-B-sqr
c14b
t(D))/(2*A); x1=(c+b*y1)/(-a);
y2=(-B+sqrt(D))/(2*A); x2=(c+b*y2)/(-a);
}
p.push_back((Point){x1,y1,0});
p.push_back((Point){x2,y2,0});
}
}
int ans=1;
for(int i=0;i<p.size();i++)ans=max(ans,check(p[i]));
cout<<ans<<endl;
}
return 0;
}
相关文章推荐
- HDU 3561 How many times 【计算几何】
- (hdu step 2.3.4)How Many Trees?(大数:求n个节点能够成多少棵二叉树)
- HDU 1555 How many days?
- HDU 1978 How many ways(动态规划)
- hdu 3038 How Many Answers Are Wrong(种类并查集)2009 Multi-University Training Contest 13
- HDU 3038 How Many Answers Are Wrong (带权并查集)
- HDU 1555 How many days?
- HDU 1213 how many tables
- HDU-1978-How many ways
- hdu 2138 How many prime numbers
- hdu-1796 How many integers can you find(容斥原理)
- hdu 3038 How Many Answers Are Wrong【并查集的简单应用】
- hdu 1978 How Many Ways
- HDU 5137:How Many Maos Does the Guanxi Worth【Floyd】
- HDU - 5137 How Many Maos Does the Guanxi Worth
- 【容斥原理】HDU-1796-How many integers can you find
- 矩阵十大经典题目之八-hdu-2157-How many ways??
- HDU2.1.2 How many prime numbers
- HDU 1978 How Many Ways
- ACM刷题之HDU————How Many Trees?