第三周 9.12 --- 9.18

9.12

hdu 3264 Open-air shopping malls

给出 n 个圆,求这样的一个圆的最小半径,(圆心为 这 n 个圆中的一个,且能够覆盖这 n 个圆 的一半面积)

枚举圆心,二分半径

好像没有卡精度,没有用eps ...

  1 #include <cstdio>
  2 #include <algorithm>
  3 #include <cmath>
  4 #include <iomanip>
  5 #include <vector>
  6 #include <iostream>
  7 using namespace std;
  8 
  9 const double PI = acos(-1.0);
 10 const int INF = (1<<30)-1;
 11 
 12 //lrj计算几何模板
 13 struct Point
 14 {
 15     double x,y;
 16     Point(double x=0,double y=0) :x(x),y(y) {}
 17 };
 18 typedef Point Vector;
 19 
 20 Point read_point(void)
 21 {
 22     double x, y;
 23     scanf("%lf%lf", &x, &y);
 24     return Point(x, y);
 25 }
 26 
 27 const double EPS = 1e-10;
 28 
 29 //向量+向量=向量 点+向量=点
 30 Vector operator + (Vector A, Vector B)    { return Vector(A.x + B.x, A.y + B.y); }
 31 
 32 //向量-向量=向量 点-点=向量
 33 Vector operator - (Vector A, Vector B)    { return Vector(A.x - B.x, A.y - B.y); }
 34 
 35 //向量*数=向量
 36 Vector operator * (Vector A, double p)    { return Vector(A.x*p, A.y*p); }
 37 
 38 //向量/数=向量
 39 Vector operator / (Vector A, double p)    { return Vector(A.x/p, A.y/p); }
 40 
 41 bool operator < (const Point& a, const Point& b)
 42 { return a.x < b.x || (a.x == b.x && a.y < b.y); }
 43 
 44 int dcmp(double x)
 45 { if(fabs(x) < EPS) return 0; else return x < 0 ? -1 : 1; }
 46 
 47 bool operator == (const Point& a, const Point& b)
 48 { return dcmp(a.x-b.x) == 0 && dcmp(a.y-b.y) == 0; }
 49 
 50 /**********************基本运算**********************/
 51 
 52 //点积
 53 double Dot(Vector A, Vector B)
 54 { return A.x*B.x + A.y*B.y; }
 55 //向量的模
 56 double Length(Vector A)    { return sqrt(Dot(A, A)); }
 57 
 58 //向量的夹角,返回值为弧度
 59 double Angle(Vector A, Vector B)
 60 { return acos(Dot(A, B) / Length(A) / Length(B)); }
 61 
 62 //叉积
 63 double Cross(Vector A, Vector B)
 64 { return A.x*B.y - A.y*B.x; }
 65 
 66 //向量AB叉乘AC的有向面积
 67 double Area2(Point A, Point B, Point C)
 68 { return Cross(B-A, C-A); }
 69 
 70 //向量A旋转rad弧度
 71 Vector VRotate(Vector A, double rad)
 72 {
 73     return Vector(A.x*cos(rad) - A.y*sin(rad), A.x*sin(rad) + A.y*cos(rad));
 74 }
 75 
 76 /**********************圆的相关计算**********************/
 77 struct Line
 78 {//有向直线
 79     Point p;
 80     Vector v;
 81     double ang;
 82     Line()    { }
 83     Line(Point p, Vector v): p(p), v(v)    { ang = atan2(v.y, v.x); }
 84     Point point(double t)
 85     {
 86         return p + v*t;
 87     }
 88     bool operator < (const Line& L) const
 89     {
 90         return ang < L.ang;
 91     }
 92 };
 93 
 94 struct Circle
 95 {
 96     Point c;
 97     double r;    //半径
 98     Point point(double a)
 99     {//求对应圆心角的点
100         return Point(c.x + r*cos(a), c.y + r*sin(a));
101     }
102 };
103 
104 double sqr(double x){return x*x;}
105 
106 double Dis(Point a,Point b){
107     double l = sqr(a.x-b.x);
108     double r = sqr(a.y-b.y);
109     return sqrt(sqr(a.x-b.x) + sqr(a.y-b.y));
110 }
111 
112 double Intersection_area(Circle a,Circle b){  
113         double dis=Dis(a.c,b.c);
114         if(a.r==0||b.r==0||dis>=a.r+b.r)return 0;  
115         else if(dis<=fabs(a.r-b.r))return PI*sqr(min(a.r,b.r));  
116         else{  
117             double angA = 2*acos( (sqr(a.r)+sqr(dis)-sqr(b.r))/(2*a.r*dis) );  
118             double angB = 2*acos( (sqr(b.r)+sqr(dis)-sqr(a.r))/(2*b.r*dis) );  
119             double areaA = sqr(a.r)*(angA-sin(angA))/2;  
120             double areaB = sqr(b.r)*(angB-sin(angB))/2;  
121             return areaA+areaB;  
122         }  
123 }
124 
125 Circle a[55],o;
126 int n;
127 double s[55];
128 
129 int ok(double r){
130     o.r = r;
131     int cnt = 0;
132     for(int i = 1;i <= n;i++){
133         double tmp = Intersection_area(o,a[i]);
134         if(tmp >= s[i]) cnt++;
135     }
136     return cnt == n;
137 }
138 
139 void solve(){
140     double lb = 0.0,ub = 1.0*INF,mid;
141     double ans = 1.0*INF;
142     for(int i = 1;i <= n;i++){
143         o.c = a[i].c;
144         lb = 0.0,ub = 1.0*INF;
145         for(int k = 1;k <= 100;k++){
146             mid = 0.5*(lb+ub);
147             if(ok(mid)) ub = mid;
148             else lb = mid;
149         }
150         ans = min(ans,mid);
151     }
152     printf("%.4lf\n",ans);
153 }
154 
155 int main(){
156     int T;
157     scanf("%d",&T);
158     while(T--){
159         scanf("%d",&n);
160         for(int i = 1;i <= n;i++){
161             scanf("%lf %lf %lf",&a[i].c.x,&a[i].c.y,&a[i].r);
162         }
163         for(int i = 1;i <= n;i++){
164             s[i] = PI*a[i].r*a[i].r;
165             s[i] = 0.5*s[i];
166         }
167         solve();
168     }
169     return 0;
170 }
View Code

 

9.13

每天上班,找工作,笔试做一堆感觉不管做得好还是不好都收不到通知,工作难找感觉都没法好好写题了..要坑死了..

暑假的内推感觉好多卡掉简历了...

诶...

 9.15

马一下..计算几何的总结

http://blog.csdn.net/lj94093/article/details/45064711

转载于:https://www.cnblogs.com/wuyuewoniu/p/5866606.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值