poj1106

Posted mxang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了poj1106相关的知识,希望对你有一定的参考价值。

极角排序扫一圈。

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

技术图片
 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的主要内容,如果未能解决你的问题,请参考以下文章

POJ1106极角排序

POJ2778DNA Sequence(AC自动机)

POJ3691DNA repair(AC自动机,DP)

18.06.03 POJ 4126:DNA 15年程设期末05(状压DP)

UVA10360 POJ1916 Rat Attack枚举

poj 1011 sticks 解题。