给你半圆的圆心和半径,还有一些点,求能在半圆内的最多的点数。
><。。才发现,我2了,排序干嘛啊><。。。
输入的时候筛掉半径大于r的点,然后枚举即可><。。。用叉积,判断在同一方向,就是在这个180°内。
我开始按极角排序了,后来想想,完全不用><。。。排序我还纠结了老半天。。。这题真是水题啊啊啊
#include <queue> #include <stack> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <iostream> #include <limits.h> #include <string.h> #include <algorithm> using namespace std; const int MAX = 155; const double eps = 1e-10; typedef struct point{ double x,y; }point; point st,c[MAX]; int cou,n; double r; bool dy(double x,double y) // x > y { return x > y + eps; } bool xy(double x,double y) // x < y { return x < y - eps; } bool dyd(double x,double y) // x >= y { return x > y - eps; } bool xyd(double x,double y) // x <= y { return x < y + eps; } bool dd(double x,double y) // x == y { return fabs( x - y ) < eps; } double dis(point a,point b) { return sqrt((a.x - b.x)*(a.x - b.x)+(a.y - b.y)*(a.y - b.y)); } double crossProduct(point a,point b,point c)//向量 ac 在 ab 的方向 { return (c.x - a.x)*(b.y - a.y) - (b.x - a.x)*(c.y - a.y); } void solve() { int count; int mmax = 1; for(int i=0; i<n; i++) { count = 1; for(int k=0; k<n; k++) if( k != i && dyd(crossProduct(st,c[i],c[k]),0.0) ) count++; if( count > mmax ) mmax = count; } printf("%d/n",mmax); } int main() { double cx,cy; while( ~scanf("%lf %lf %lf",&cx,&cy,&r) ) { if( xy(r,0.0) ) break; st.x = cx; st.y = cy; scanf("%d",&n); cou = 0; point tmp; for(int i=0; i<n; i++) { scanf("%lf %lf",&tmp.x,&tmp.y); if( xyd(dis(tmp,st),r) ) c[cou++] = tmp; } n = cou; if( n == 0 ) { printf("0/n"); continue; } solve(); } return 0; }