Description
以雷达心为圆心的半圆形雷达覆盖范围有多个点 雷达可旋转,求最多覆盖数(含在边界的)
Input
Output
Sample Input
25 25 3.5------雷达坐标与半径 7----------点数 25 28-------点坐标 23 27 27 27 24 23 26 23 24 29 26 29 350 200 2.0 5 350 202 350 199 350 198 348 200 352 200 995 995 10.0 4 1000 1000 999 998 990 992 1000 999 100 100 -2.5 Sample Output
3 4 4 做法:每个点与中点都组成一个直线方程完后线性规划看其他的点在这条直线左边的inc(s)在右边的inc(b)在直线的inc(m),完后比较m+s与max的大小和b+m与max的大小 代码如下:
#include <iostream> #include <cstdio> #include <cmath> using namespace std; int ry,rx,n,x[10000],y[10000]; double r; int main() { int q,p,t,m,b,s,max; while (~scanf("%d%d%lf",&rx,&ry,&r)&&r>0) { cin>>n; t=0; max=0; for (int i=1;i<=n;i++) { cin>>q>>p; if (sqrt((q-rx)*(q-rx)+(p-ry)*(p-ry))<=r) { t++; x[t]=q; y[t]=p; } } for (int i=1;i<=t;i++) { m=0;b=0;s=0; for (int j=1;j<=t;j++) { if ((y[j]-ry)*(x[i]-rx)-(x[j]-rx)*(y[i]-ry)==0) m++; if ((y[j]-ry)*(x[i]-rx)-(x[j]-rx)*(y[i]-ry)<0) s++; if ((y[j]-ry)*(x[i]-rx)-(x[j]-rx)*(y[i]-ry)>0) b++; } if (b+m>max) max=b+m; if (s+m>max) max=s+m; } cout<<max<<endl; } }