直接枚舉!
Accepted | 1041 | C++ | 00:00.00 | 396K |
#include<math.h>
#include<stdlib.h>
#define dis(a,b) sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y))
typedef struct s
{
int x;
int y;
}point;
int direction(point p1,point p2,point p3)
{//大於零順時針小於零逆時針(p1=>p2)
return (p2.x - p1.x) * (p3.y - p1.y) - (p3.x - p1.x) * (p2.y - p1.y);
}
void solve(point t,float radius)
{
int i,cnt,res = 0,n;
scanf("%d",&n);
point* pt = (point*)malloc(sizeof(point) * n);
for(i = 0,cnt = 0; i < n; i++)
{
point temp;
scanf("%d%d",&temp.x,&temp.y);
if(dis(temp,t) <= radius)
{
pt[cnt].x = temp.x;
pt[cnt++].y = temp.y;
}
}
for(i = 0; i < cnt; i++)
{
int temp = 0;
for(int j = 0; j < cnt; j++)
{
if(i == j) continue;
if(direction(pt[i],pt[j],t) > 0)//這裏無所謂大於零還是小於零的,只要是同一方向就行
temp++;
}
temp = temp > cnt - temp ? temp : cnt - temp;
res = res > temp ? res : temp;
}
free(pt);
printf("%d/n",res);
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("1041.txt","r",stdin);
freopen("ans.txt","w",stdout);
#endif
point t;
float radius;
while(scanf("%d%d%f",&t.x,&t.y,&radius) != EOF && radius >= 0)
solve(t,radius);
#ifndef ONLINE_JUDGE
fclose(stdin);
fclose(stdout);
#endif
return 0;
}