关闭

zoj1041 Transmitters

850人阅读 评论(0) 收藏 举报
  1. //zoj1041 Transmitters
  2. //Accepted 1041 C++ 00:00.00 424K
  3. #include <stdio.h>
  4. #include <math.h>
  5. #define MAXN 1000
  6. struct point {double x,y;}c;
  7. double r;
  8. double xmult(double x1,double y1,double x2,double y2){return x1*y2-x2*y1;}
  9. double dist(point p1,point p2){ return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));}
  10.  
  11. void solve()
  12. {
  13.        int i,j,n,num,max,cnt;
  14.        double dx,dy,dt;
  15.        point pt,p[MAXN];
  16.        scanf ("%d",&n);
  17.        num = 0;
  18.        for (i=0; i<n; ++i) {
  19.               scanf ("%lf %lf",&pt.x,&pt.y);
  20.               if (dist(pt,c)<=r) p[num++] = pt;
  21.        }
  22.        if (num<=2){
  23.               printf ("%d/n",num);
  24.               return ;
  25.        }
  26.        max = 2;
  27.        for (i=0; i<num; ++i){
  28.               cnt = 1;
  29.               dy = p[i].y-c.y;
  30.               dx = p[i].x-c.x;
  31.               for (j=0; j<num; ++j){
  32.                      if (i==j) continue;
  33.                      if (xmult(p[j].x-c.x,p[j].y-c.y,dx,dy)>=0.0) cnt++;
  34.               }
  35.               if (cnt>max) max = cnt;
  36.        }
  37.        printf ("%d/n",max);
  38. }
  39.  
  40. int main()
  41. {
  42. #ifdef ONLINE_JUDGE
  43. #else
  44.        freopen("1041.txt","r",stdin);
  45. #endif
  46.        while (scanf("%lf %lf %lf",&c.x,&c.y,&r)!=EOF){
  47.               if (r<=0.0) break;
  48.               solve();
  49.        }
  50. #ifdef ONLINE_JUDGE
  51. #else
  52.        fclose(stdin);
  53. #endif
  54.        return 0;
  55. }
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:36761次
    • 积分:664
    • 等级:
    • 排名:千里之外
    • 原创:33篇
    • 转载:0篇
    • 译文:0篇
    • 评论:10条
    文章分类
    最新评论