设为首页 加入收藏

TOP

POJ 1106 Transmitters (简单计算几何)
2015-07-20 17:40:54 来源: 作者: 【 】 浏览:2
Tags:POJ 1106 Transmitters 简单 计算 几何

?

Transmitters

?

题目大意:给你一个半圆的圆心跟半径,再给你N个点,半圆可以绕圆心旋转任意角度,求半圆最多可以覆盖的点的个数是多少。

?

解题思路:因为圆心是固定的,就很简单了。先把在圆的覆盖范围内的点找出来,再对这些点循环去找对于每个点来说,跟它在同一侧的点的个数,同侧的点判断就用叉积就可以,当叉积>=0的时候就是同一侧的。

?

代码如下:

?

#include 
  
   
#include 
   
     #include 
    
      #include 
     
       #define sqr(x) ((x)*(x)) using namespace std; const double eps = 1e-8; int dcmp(double x) { return x < -eps ? -1 : x > eps; } struct Point { double x, y; } P[155]; double Distance(Point a, Point b){ return sqrt(sqr(a.x-b.x)+sqr(a.y-b.y)); } double xmult(Point a, Point b, Point c) { return (a.x-c.x)*(b.y-c.y)-(a.y-c.y)*(b.x-c.x); } int main() { Point o; double R; int n; while(~scanf(%lf%lf%lf, &o.x, &o.y, &R)) { if(dcmp(R) < 0) { break; } scanf(%d, &n); Point p; int m = 0; for(int i = 0; i < n; ++i) { scanf(%lf%lf, &p.x, &p.y); if(dcmp(Distance(p, o)-R) <= 0) { P[m++] = p; } } int ans = 0; for(int i = 0; i < m; ++i) { int num = 0; for(int j = 0; j < m; ++j) { if(dcmp(xmult(P[i], P[j], o)) >= 0) { num++; } } //printf(p%d = %lf %lf num = %d , i, P[i].x, P[i].y, num); ans = max(ans, num); } printf(%d , ans); } return 0; } 
     
    
   
  


?

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇HDU 1316-How Many Fibs?(大数类.. 下一篇POJ 3580 SuperMemo Splay 区间维..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·HTTP协议深度解析: (2025-12-25 16:21:03)
·HTTP 概述 - MDN (2025-12-25 16:21:00)
·视频直播为什么要用u (2025-12-25 16:20:57)
·用 Python 进行数据 (2025-12-25 15:49:09)
·如何学习Python数据 (2025-12-25 15:49:07)