码迷,mamicode.com
首页 > 其他好文 > 详细

poj1106

时间:2019-03-26 00:53:10      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:double   技术   mes   bsp   space   bool   abs   point   const   

极角排序扫一圈。

今天没什么状态写个水题减轻负罪感(大雾)

技术图片
 1 #include <cstdio>
 2 #include <cmath>
 3 #include <cstring>
 4 #include <algorithm>
 5 #include <vector>
 6 using namespace std;
 7 typedef double db;
 8 const db eps = 1e-6;
 9 const db pi = acos(-1);
10 int sign(db k){
11     if (k>eps) return 1; else if (k<-eps) return -1; return 0;
12 }
13 int cmp(db k1,db k2){return sign(k1-k2);}
14 struct point{
15     db x,y,ang;
16     point operator + (const point &k1) const{return (point){k1.x+x,k1.y+y};}
17     point operator - (const point &k1) const{return (point){x-k1.x,y-k1.y};}
18     point operator * (db k1) const{return (point){x*k1,y*k1};}
19     point operator / (db k1) const{return (point){x/k1,y/k1};}
20     int operator == (const point &k1) const{return cmp(x,k1.x)==0&&cmp(y,k1.y)==0;}
21     db abs(){ return sqrt(x*x+y*y);}
22     db dis(point k1){return ((*this)-k1).abs();}
23     db getw(){return atan2(y,x);}
24 };
25 struct circle{
26     point o;db r;
27     int inside(point k){return cmp(r,o.dis(k))>=0;}
28 }c;
29 vector<point> v;
30 bool cmp2(point a,point b){
31     return a.ang<b.ang;
32 }
33 int n;point t;
34 int main(){
35     while (scanf("%lf%lf%lf",&c.o.x,&c.o.y,&c.r)&&c.r>0){
36     //scanf("%lf%lf%lf",&c.o.x,&c.o.y,&c.r);
37         scanf("%d",&n);
38         while (n--){
39             scanf("%lf%lf",&t.x,&t.y);
40             if(c.inside(t)){
41                 t.ang = (c.o-t).getw();
42                 v.push_back(t);
43                 v.push_back({t.x,t.y,t.ang+2*pi});
44             }
45         }
46         sort(v.begin(),v.end(),cmp2);
47         int m = v.size()/2;
48         int ans = 0;
49         for(int l=0,r=0;l<m;l++){
50             while (r<2*m&&v[r].ang-v[l].ang<=pi)
51                 r++;
52             ans=max(ans,r-l);
53         }
54         printf("%d\n",ans);
55         v.clear();
56     }
57 }
View Code

 

poj1106

标签:double   技术   mes   bsp   space   bool   abs   point   const   

原文地址:https://www.cnblogs.com/MXang/p/10597596.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!