hdu3264Open-air shopping malls(二分)

链接

枚举伞的圆心,最多只有20个,因为必须与某个现有的圆心重合。

然后再二分半径就可以了。

 1 #include <iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 #include<stdlib.h>
 6 #include<vector>
 7 #include<cmath>
 8 #include<queue>
 9 #include<set>
10 using namespace std;
11 #define N 25
12 #define LL long long
13 #define INF 0xfffffff
14 const double eps = 1e-8;
15 const double pi = acos(-1.0);
16 const double inf = ~0u>>2;
17 struct point
18 {
19     double x,y;
20     double r,s;
21     point(double x=0,double y=0):x(x),y(y) {}
22 } p[N];
23 int n;
24 typedef point pointt;
25 pointt operator -(point a,point b)
26 {
27     return point(a.x-b.x,a.y-b.y);
28 }
29 int dcmp(double x)
30 {
31     if(fabs(x)<eps) return 0;
32     return x<0?-1:1;
33 }
34 double circle_area(point a,point b)
35 {
36     double s,d,t,t1;
37     d=sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
38     if(d>=a.r+b.r) s=0;
39     else if(d<=fabs(a.r-b.r)) s=min(acos(-1.0)*a.r*a.r,acos(-1.0)*b.r*b.r);
40     else
41     {
42         t=(a.r*a.r+d*d-b.r*b.r)/2.0/d;
43         t1=sqrt(a.r*a.r-t*t);
44         s=-d*t1+a.r*a.r*acos(t/a.r)+b.r*b.r*acos((d-t)/b.r);
45     }
46     return s;
47 }
48 int cal(double mid,point pp)
49 {
50     int i;
51     double sum;
52     pp.r = mid;
53     for(i = 1 ; i <= n ; i++)
54     {
55         sum = circle_area(pp,p[i]);
56         if(dcmp(sum-p[i].s/2)<0) return 0;
57     }
58     //cout<<mid<<" "<<pp.x<<" "<<pp.y<<" "<<pp.r<<endl;
59     return 1;
60 }
61 double solve(point pp)
62 {
63     double rig = 20001,lef = 0,mid;
64     while(rig-lef>eps)
65     {
66         mid = (rig+lef)/2;
67         if(cal(mid,pp))
68         rig = mid;
69         else lef = mid;
70     }
71     return rig;
72 }
73 int main()
74 {
75     int t,i;
76     cin>>t;
77     while(t--)
78     {
79         scanf("%d",&n);
80         for(i = 1; i <= n ; i++)
81         {
82             scanf("%lf%lf%lf",&p[i].x,&p[i].y,&p[i].r);
83             p[i].s = pi*p[i].r*p[i].r;
84         }
85         double ans = INF;
86         for(i = 1; i <= n ; i++)
87         {
88             ans = min(ans,solve(p[i]));
89         }
90         printf("%.4f\n",ans);
91     }
92     return 0;
93 }

hdu3264Open-air shopping malls(二分)

时间: 2024-08-01 21:21:10

hdu3264Open-air shopping malls(二分)的相关文章

hdu 3264 Open-air shopping malls(求圆相交的面积,二分)

Open-air shopping malls Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2256    Accepted Submission(s): 837 Problem Description The city of M is a famous shopping city and its open-air shopping

HDU 3264 Open-air shopping malls (两个圆的交面积+二分)

题目链接 :HDU 3264 Open-air shopping malls 题意:给出n个圆.要求一个在n个圆的圆心建一个大圆,使大圆与每一个小圆的交面积大于等于该小圆的面积的一般.求最小的大圆半径. 思路:二分大圆半径,枚举每个小圆与大圆的交面积. 注意精度问题. AC代码: #include <stdio.h> #include <math.h> #include <algorithm> const double eps=1e-6; const double PI

Open-air shopping malls(二分半径,两元交面积)

http://acm.hdu.edu.cn/showproblem.php?pid=3264 Open-air shopping malls Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2139    Accepted Submission(s): 775 Problem Description The city of M is a

hdu 3264 09 宁波 现场 E - Open-air shopping malls 计算几何 二分

Description The city of M is a famous shopping city and its open-air shopping malls are extremely attractive. During the tourist seasons, thousands of people crowded into these shopping malls and enjoy the vary-different shopping. Unfortunately, the

HDU 3264 Open-air shopping malls(圆相交面积+二分)

HDU 3264 Open-air shopping malls(圆相交面积+二分) ACM 题目地址:HDU 3264 Open-air shopping malls 题意: 给出一些圆,选择其中一个圆的圆心为圆心,然后画一个大圆,要求大圆最少覆盖每个圆的一半面积.求最小面积. 分析: 枚举每个点,用二分求出需要的圆,更新最小值即可. 其中用到了圆相交面积,可以参考这题: POJ 2546 Circular Area(两个圆相交面积) 代码: /* * Author: illuz <iillu

hdu 3264 Open-air shopping malls 求两圆相交

对每个圆二分半径寻找可行的最小半径,然后取最小的一个半径. 对于两圆相交就只要求到两个扇形,然后减去两个全等三角形就行了. #include<cstdio> #include<iostream> #include<cmath> #include<algorithm> using namespace std; #define pi acos(-1.0) #define eps 1e-8 #define maxn 50 int n; struct point{

POJ 3831 &amp; HDU 3264 Open-air shopping malls(几何)

题目链接: POJ:http://poj.org/problem?id=3831 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=3264 Description The city of M is a famous shopping city and its open-air shopping malls are extremely attractive. During the tourist seasons, thousands of people

[hdu 3264] Open-air shopping malls(二分+两圆相交面积)

题目大意是:先给你一些圆,你可以任选这些圆中的一个圆点作圆,这个圆的要求是:你画完以后.这个圆要可以覆盖之前给出的每一个圆一半以上的面积,即覆盖1/2以上每一个圆的面积. 比如例子数据,选左边还是选右边没差别,红色的圆为答案(选了左边的圆点),它覆盖了左边圆的1/2以上,也覆盖了右边圆的1/2以上. 知道了怎样求两圆面积交.那么这道题就简单了.仅仅要二分答案,然后枚举每个圆点,假设全都覆盖了1/2以上就继续二分,最后答案就得出来了. #include<iostream> #include<

HDU3264 Open-air shopping malls (圆交+二分)

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3264 题意: 给定n个圆的圆心和半径,求一个圆心为这些圆中任意一个,与所有圆相交的面积超过其面积一半的圆的最小半径. 分析: 枚举圆心,然后二分得到最小的半径,直接套求圆交的模板. 代码如下: #include <iostream> #include <cstring> #include <cstdio> #include <cmath> using name