# Where_Free

## 2019年广东外语外贸大学程序设计竞赛（新手赛）-F题（好快的刀）题解

 1 #include <iostream>
2 #include <cmath>
3 using namespace std;
4 const double eps=1e-8;
5 const double inf =1e20;
6 //const double pi=acos(-1.0);
7 int sgn(double x){
8     if(fabs(x)<eps) return 0;
9     if(x<0) return -1;
10     else return 1;
11 }
12 struct Point{
13     double x,y;
14     Point(){}
15     Point(double _x,double _y){
16         x=_x;
17         y=_y;
18     }
19     void input(){
20         scanf("%lf%lf",&x,&y);
21     }
22     bool operator ==(Point b)const{
23         return sgn(x-b.x)==0&&sgn(y-b.y)==0;
24     }
25     Point operator -(const Point &b)const{
26         return Point(x-b.x,y-b.y);
27     }
28     double operator ^(const Point &b)const{
29         return x*b.y-y*b.x;
30     }
31     double distance(Point p){
32         return hypot(x-p.x,y-p.y);
33     }
34 };
35 struct Line{
36     Point s,e;
37     void input(){
38         s.input();
39         e.input();
40     }
41     double length(){
42         return s.distance(e);
43     }
44     double dispointtoline(Point p){
45         return fabs((p-s)^(e-s))/length();
46     }
47 };
48 struct circle{
49     Point p;
50     double r;
51     void input(){
52         p.input();
53         scanf("%lf",&r);
54     }
55     bool operator ==(circle v){
56         return (p==v.p);
57     }
58     int relationline(Line v){
59         double dst=v.dispointtoline(p);
60         if(sgn(dst-r)<0) return 2;
61         else if(sgn(dst-r)==0) return 1;
62         else return 0;
63     }
64
65 };
66 int main(){
67     int n,ans(2),cou,flag(0);
68     circle cir[105];
69     Line line1;
70     cin>>n;
71     for(int i=0;i<n;i++) cir[i].input();
72     for(int i=0;i<n;i++){
73         if(cir[i]==cir[0]&&i==n-1)flag=1;
74     }
75     if(flag){
76         cout<<n<<'\n';
77         return 0;
78     }
79     for(int i=0;i<n;i++){
80         for(int j=0;j<n;j++){
81             cou=2;
82             if(i==j) continue;
83             line1.e=cir[i].p;
84             line1.s=cir[j].p;
85             for(int k=0;k<n;k++){
86                 if(k==i||k==j) continue;
87                 if(cir[k].relationline(line1)!=0) cou++;
88             }
89             ans=max(ans,cou);
90         }
91     }
92     cout<<ans<<'\n';
93     return 0;
94 }

posted on 2019-11-23 00:25  Where_Free  阅读(81)  评论(0编辑  收藏

• 随笔 - 37
• 文章 - 0
• 评论 - 3