题目链接:http://poj.org/problem?id=1106

算法思路:由于圆心和半径都确定,又是180度,这里枚举过一点的直径,求出这个直径的一个在圆上的端点,就可以用叉积的大于,等于,小于0判断点在直径上,左,右。 这里要记录直径两边的加直径上的点的个数,去最大的。

代码:

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<cmath>
  4. #include<iostream>
  5. #include<algorithm>
  6. #include<queue>
  7. using namespace std;
  8.  
  9. const double eps = 1e-;
  10. const double PI = acos(-1.0);
  11. const double INF = 1000000000000000.000;
  12.  
  13. struct Point{
  14. double x,y;
  15. Point(double x=, double y=) : x(x),y(y){ } //构造函数
  16. };
  17. typedef Point Vector;
  18.  
  19. struct Circle{
  20. Point c;
  21. double r;
  22. Circle() {}
  23. Circle(Point c,double r): c(c),r(r) {}
  24. };
  25. Vector operator + (Vector A , Vector B){return Vector(A.x+B.x,A.y+B.y);}
  26. Vector operator - (Vector A , Vector B){return Vector(A.x-B.x,A.y-B.y);}
  27. Vector operator * (double p,Vector A){return Vector(A.x*p,A.y*p);}
  28. Vector operator / (Vector A , double p){return Vector(A.x/p,A.y/p);}
  29.  
  30. bool operator < (const Point& a,const Point& b){
  31. return a.x < b.x ||( a.x == b.x && a.y < b.y);
  32. }
  33.  
  34. int dcmp(double x){
  35. if(fabs(x) < eps) return ;
  36. else return x < ? - : ;
  37. }
  38. bool operator == (const Point& a, const Point& b){
  39. return dcmp(a.x - b.x) == && dcmp(a.y - b.y) == ;
  40. }
  41.  
  42. ///向量(x,y)的极角用atan2(y,x);
  43. inline double Dot(Vector A, Vector B){ return A.x*B.x + A.y*B.y; }
  44. inline double Length(Vector A) { return sqrt(Dot(A,A)); }
  45. inline double Angle(Vector A, Vector B) { return acos(Dot(A,B) / Length(A) / Length(B)); }
  46. double Cross(Vector A, Vector B) { return A.x*B.y - A.y * B.x; }
  47. Vector vecunit(Vector v){ return v / Length(v);} //单位向量
  48.  
  49. Point read_point(){
  50. Point A;
  51. scanf("%lf %lf",&A.x,&A.y);
  52. return A;
  53. }
  54.  
  55. //多边形
  56. //求面积
  57. double PolygonArea(Point* p,int n){ //n个点
  58. double area = ;
  59. for(int i=;i<n-;i++){
  60. area += Cross(p[i]-p[],p[i+]-p[]);
  61. }
  62. return area/;
  63. }
  64.  
  65. /*************************************分 割 线*****************************************/
  66.  
  67. int main()
  68. {
  69. //freopen("E:\\acm\\input.txt","r",stdin);
  70.  
  71. Point O,P[];
  72. double R;
  73.  
  74. while(scanf("%lf %lf %lf",&O.x,&O.y,&R) == && dcmp(R)>)
  75. {
  76. int N;
  77. cin>>N;
  78. int cnt = ;
  79. for(int i=;i<=N;i++)
  80. {
  81. Point temp = read_point();
  82. double len = Length(temp-O);
  83. if(dcmp(len-R) > ) continue;
  84. P[++cnt] = temp;
  85. }
  86. int ans = ;
  87. for(int i=; i<=cnt; i++)
  88. {
  89. if(P[i] == O)
  90. {
  91. ans = max(ans,);
  92. continue;
  93. }
  94. int lnum = ;
  95. int rnum = ;
  96. Vector v = P[i] - O;
  97. v = (-1.0)*vecunit(v);
  98. Point T = O + R*v;
  99. for(int j=; j<=cnt; j++)
  100. {
  101. if(i == j) continue;
  102. if(dcmp(Cross(P[j]-T,O-T)) > ) lnum++;
  103. else if(dcmp(Cross(P[j]-T,O-T)) == ) lnum++,rnum++;
  104. else rnum++;
  105. }
  106.  
  107. int num = max(lnum,rnum);
  108. ans = max(ans,num);
  109. }
  110. printf("%d\n",ans);
  111. }
  112. }

poj 1106 Transmitters (枚举+叉积运用)的更多相关文章

  1. Poj 1106 Transmitters

    Poj 1106 Transmitters 传送门 给出一个半圆,可以任意旋转,问这个半圆能够覆盖的最多点数. 我们枚举每一个点作为必然覆盖点,那么使用叉积看极角关系即可判断其余的点是否能够与其存在一 ...

  2. poj 1106 Transmitters (叉乘的应用)

    http://poj.org/problem?id=1106 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4488   A ...

  3. POJ 1106 Transmitters(计算几何)

    题目链接 切计算几何,感觉计算几何的算法还不熟.此题,枚举线段和圆点的直线,平分一个圆 #include <iostream> #include <cstring> #incl ...

  4. poj 1873 凸包+枚举

    The Fortified Forest Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 6198   Accepted: 1 ...

  5. POJ 3304 Segments【叉积】

    题意:有n条线段,问有没有一条直线使得所有线段在这条直线上的投影至少有一个共同点. 思路:逆向思维,很明显这个问题可以转化为是否有一条直线穿过所有线段,若有,问题要求的直线与该直线垂直,并且公共点为垂 ...

  6. POJ 1018 【枚举+剪枝】.cpp

    题意: 给出n个工厂的产品参数带宽b和价格p,在这n个工厂里分别选1件产品共n件,使B/P最小,其中B表示n件产品中最小的b值,P表示n件产品p值的和. 输入 iCase n 表示iCase个样例n个 ...

  7. POJ 3977 折半枚举

    链接: http://poj.org/problem?id=3977 题意: 给你n个数,n最大35,让你从中选几个数,不能选0个,使它们和的绝对值最小,如果有一样的,取个数最小的 思路: 子集个数共 ...

  8. poj 1269 Intersecting Lines——叉积求直线交点坐标

    题目:http://poj.org/problem?id=1269 相关知识: 叉积求面积:https://www.cnblogs.com/xiexinxinlove/p/3708147.html什么 ...

  9. poj 2318 TOYS &amp; poj 2398 Toy Storage (叉积)

    链接:poj 2318 题意:有一个矩形盒子,盒子里有一些木块线段.而且这些线段坐标是依照顺序给出的. 有n条线段,把盒子分层了n+1个区域,然后有m个玩具.这m个玩具的坐标是已知的,问最后每一个区域 ...

随机推荐

  1. JQuery 多个ID对象绑定一个click事件

    一.表单的多个radio对象绑定click: $("#ImgRadio :radio").click(function(){ func(); });

  2. 关于vs2008使用oracleclient链接oracle数据库报报错OCIEnvCreate 失败,返回代码为 -1,但错误消息文本不可用

    用vs2008链接oracle数据库出现问题,报错OCIEnvCreate 失败,返回代码为 -1,但错误消息文本不可用,从网上找了好久方法,有两种oracle客户端文件权限,和运行vs2008以管理 ...

  3. help python(查看模块帮助文档)

    查看模块帮助文档: help(len) -- docs for the built in len function (note here you type "len" not &q ...

  4. jQuery 效果方法

    jQuery 效果方法 下面的表格列出了所有用于创建动画效果的 jQuery 方法. 方法 描述 animate() 对被选元素应用"自定义"的动画 clearQueue() 对被 ...

  5. C语言带参数的main函数

    C语言带参数的main函数 #include<stdio.h> int main(int argc,char*argv[]) { int i; ;i<argc;i++) printf ...

  6. 关于boost::function与boost::bind函数的使用心得

    最近开始写一个线程池,期间想用一个通用的函数模板来使得各个线程执行不同的任务,找到了Boost库中的function函数. Boost::function是一个函数包装器,也即一个函数模板,可以用来代 ...

  7. 子网/ip/子网掩码

    IP地址由网络地址和主机地址组成 而现在IP由“子网掩码”通过子网网络地 址细分出 A,B,C类更小的网络.这种方式 实际上就是将原来的A类,B类,C类等分类 中的的主机地址部分用作子网地址,可以 将 ...

  8. c#写个基础的Socket通讯

    晚上想写点东西,想想把我刚来公司学的Sockt通讯写上来吧.要写的简单易懂点,新人们可以借鉴下哦,用控制台写. 先得说说Socket,与TCP/UDP啥关系,一直讲什么Socket通讯,TCP通讯,都 ...

  9. javascript 自定义鼠标右键菜单

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...

  10. 使用PHP脚本来写Daemon程序

    什么是Daemon进程   这又是一个有趣的概念,daemon在英语中是"精灵"的意思,就像我们经常在迪斯尼动画里见到的那些,有些会飞,有些不会,经常围着动画片的主人公转来转去,啰 ...