2019 Guangdong University of Foreign Studies Programming Contest (novice race) -F title (good fast knife) explanations

Questions surface:

 

 

Title means, the center forms a straight line connecting any two circles, calculating the number of circle tangent to or intersects with the straight line, a straight line up to the required number of intersecting or tangent to a circle

Problem-solving ideas:

Through all of the circle, the straight line is calculated to generate two circle center, and then traversing another circle, the radius of the circle and the detected distance to the center line, to confirm the relationship between line and circle.

Pit:

Addressing a function idea, consider the slope is not a problem (with vector can circumvent this problem solved)

All are both concentric circle, need special judge (match test data does not take this particular case, after the game discovered by a gangster at Guangzhou University, would like to thank)

Standard process:

When questions were out of hand method and the method of vector functions rub the two codes, and finally with the standard process is to write the template kuangbin

Precision vector method is higher than the accuracy of the method functions, but it is difficult to reduce or relax the range accuracy (big brother can not say too young cancer)

 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 }

Finally, very sorry not take into account special circumstances when the topic of concentric circles, causing the test data is not perfect, hereby apologize.

Guess you like

Origin www.cnblogs.com/Never-Land/p/11914984.html