中石油大D:Go Fishing
求点(x, y)极坐标下的角度 double x = atan2(y, x);//此时的x是一个正切值 (atan2 返回以弧度表示的 y/x 的反正切) x * 180 / 3.14;
#include<iostream> #include<cmath> #include<algorithm> #include<cstdio> typedef long long ll; using namespace std; double r; int n; double eps = 1e-6; const int N = 1e2 + 10; struct pts { double x, y; }p[N]; double dis(pts a, pts b){ return sqrt((a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y - b.y)); } pts center(pts a, pts b) { pts mid; mid.x = (a.x + b.x) / 2; mid.y = (a.y + b.y) / 2; double distance = dis(mid, a); double h = sqrt(r * r - distance * distance); double th = -1 * atan2(a.x - b.x, a.y - b.y);// 使用的是相反的角, 所以需要y和x倒置, 还需要乘以-1 // double th = atan2(a.y - b.y, a.x - b.x); pts p; p.x = mid.x + h * cos(th); p.y = mid.y + h * sin(th); return p; } int main(){ scanf("%lf",&r); scanf("%d",&n); for(int i = 0; i < n; i++){ scanf("%lf%lf",&p[i].x,&p[i].y); } ll ans = 1; for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ if(i == j) continue; // if(dis(p[i],p[j]) > 2*r) continue; pts m = center(p[i],p[j]); ll cnt = 0; for(int k = 0; k < n; k++){ if(dis(m,p[k]) < r + eps) cnt++; } ans = max(ans,cnt); } } printf("%lld",ans); return 0; }