poj 1106 Transmitters (枚举+叉积运用)
题目链接:http://poj.org/problem?id=1106
算法思路:由于圆心和半径都确定,又是180度,这里枚举过一点的直径,求出这个直径的一个在圆上的端点,就可以用叉积的大于,等于,小于0判断点在直径上,左,右。 这里要记录直径两边的加直径上的点的个数,去最大的。
代码:
- #include<cstdio>
- #include<cstring>
- #include<cmath>
- #include<iostream>
- #include<algorithm>
- #include<queue>
- using namespace std;
- const double eps = 1e-;
- const double PI = acos(-1.0);
- const double INF = 1000000000000000.000;
- struct Point{
- double x,y;
- Point(double x=, double y=) : x(x),y(y){ } //构造函数
- };
- typedef Point Vector;
- struct Circle{
- Point c;
- double r;
- Circle() {}
- Circle(Point c,double r): c(c),r(r) {}
- };
- Vector operator + (Vector A , Vector B){return Vector(A.x+B.x,A.y+B.y);}
- Vector operator - (Vector A , Vector B){return Vector(A.x-B.x,A.y-B.y);}
- Vector operator * (double p,Vector A){return Vector(A.x*p,A.y*p);}
- Vector operator / (Vector A , double p){return Vector(A.x/p,A.y/p);}
- bool operator < (const Point& a,const Point& b){
- return a.x < b.x ||( a.x == b.x && a.y < b.y);
- }
- int dcmp(double x){
- if(fabs(x) < eps) return ;
- else return x < ? - : ;
- }
- bool operator == (const Point& a, const Point& b){
- return dcmp(a.x - b.x) == && dcmp(a.y - b.y) == ;
- }
- ///向量(x,y)的极角用atan2(y,x);
- inline double Dot(Vector A, Vector B){ return A.x*B.x + A.y*B.y; }
- inline double Length(Vector A) { return sqrt(Dot(A,A)); }
- inline double Angle(Vector A, Vector B) { return acos(Dot(A,B) / Length(A) / Length(B)); }
- double Cross(Vector A, Vector B) { return A.x*B.y - A.y * B.x; }
- Vector vecunit(Vector v){ return v / Length(v);} //单位向量
- Point read_point(){
- Point A;
- scanf("%lf %lf",&A.x,&A.y);
- return A;
- }
- //多边形
- //求面积
- double PolygonArea(Point* p,int n){ //n个点
- double area = ;
- for(int i=;i<n-;i++){
- area += Cross(p[i]-p[],p[i+]-p[]);
- }
- return area/;
- }
- /*************************************分 割 线*****************************************/
- int main()
- {
- //freopen("E:\\acm\\input.txt","r",stdin);
- Point O,P[];
- double R;
- while(scanf("%lf %lf %lf",&O.x,&O.y,&R) == && dcmp(R)>)
- {
- int N;
- cin>>N;
- int cnt = ;
- for(int i=;i<=N;i++)
- {
- Point temp = read_point();
- double len = Length(temp-O);
- if(dcmp(len-R) > ) continue;
- P[++cnt] = temp;
- }
- int ans = ;
- for(int i=; i<=cnt; i++)
- {
- if(P[i] == O)
- {
- ans = max(ans,);
- continue;
- }
- int lnum = ;
- int rnum = ;
- Vector v = P[i] - O;
- v = (-1.0)*vecunit(v);
- Point T = O + R*v;
- for(int j=; j<=cnt; j++)
- {
- if(i == j) continue;
- if(dcmp(Cross(P[j]-T,O-T)) > ) lnum++;
- else if(dcmp(Cross(P[j]-T,O-T)) == ) lnum++,rnum++;
- else rnum++;
- }
- int num = max(lnum,rnum);
- ans = max(ans,num);
- }
- printf("%d\n",ans);
- }
- }
poj 1106 Transmitters (枚举+叉积运用)的更多相关文章
- Poj 1106 Transmitters
Poj 1106 Transmitters 传送门 给出一个半圆,可以任意旋转,问这个半圆能够覆盖的最多点数. 我们枚举每一个点作为必然覆盖点,那么使用叉积看极角关系即可判断其余的点是否能够与其存在一 ...
- poj 1106 Transmitters (叉乘的应用)
http://poj.org/problem?id=1106 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4488 A ...
- POJ 1106 Transmitters(计算几何)
题目链接 切计算几何,感觉计算几何的算法还不熟.此题,枚举线段和圆点的直线,平分一个圆 #include <iostream> #include <cstring> #incl ...
- poj 1873 凸包+枚举
The Fortified Forest Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 6198 Accepted: 1 ...
- POJ 3304 Segments【叉积】
题意:有n条线段,问有没有一条直线使得所有线段在这条直线上的投影至少有一个共同点. 思路:逆向思维,很明显这个问题可以转化为是否有一条直线穿过所有线段,若有,问题要求的直线与该直线垂直,并且公共点为垂 ...
- POJ 1018 【枚举+剪枝】.cpp
题意: 给出n个工厂的产品参数带宽b和价格p,在这n个工厂里分别选1件产品共n件,使B/P最小,其中B表示n件产品中最小的b值,P表示n件产品p值的和. 输入 iCase n 表示iCase个样例n个 ...
- POJ 3977 折半枚举
链接: http://poj.org/problem?id=3977 题意: 给你n个数,n最大35,让你从中选几个数,不能选0个,使它们和的绝对值最小,如果有一样的,取个数最小的 思路: 子集个数共 ...
- poj 1269 Intersecting Lines——叉积求直线交点坐标
题目:http://poj.org/problem?id=1269 相关知识: 叉积求面积:https://www.cnblogs.com/xiexinxinlove/p/3708147.html什么 ...
- poj 2318 TOYS & poj 2398 Toy Storage (叉积)
链接:poj 2318 题意:有一个矩形盒子,盒子里有一些木块线段.而且这些线段坐标是依照顺序给出的. 有n条线段,把盒子分层了n+1个区域,然后有m个玩具.这m个玩具的坐标是已知的,问最后每一个区域 ...
随机推荐
- JQuery 多个ID对象绑定一个click事件
一.表单的多个radio对象绑定click: $("#ImgRadio :radio").click(function(){ func(); });
- 关于vs2008使用oracleclient链接oracle数据库报报错OCIEnvCreate 失败,返回代码为 -1,但错误消息文本不可用
用vs2008链接oracle数据库出现问题,报错OCIEnvCreate 失败,返回代码为 -1,但错误消息文本不可用,从网上找了好久方法,有两种oracle客户端文件权限,和运行vs2008以管理 ...
- help python(查看模块帮助文档)
查看模块帮助文档: help(len) -- docs for the built in len function (note here you type "len" not &q ...
- jQuery 效果方法
jQuery 效果方法 下面的表格列出了所有用于创建动画效果的 jQuery 方法. 方法 描述 animate() 对被选元素应用"自定义"的动画 clearQueue() 对被 ...
- C语言带参数的main函数
C语言带参数的main函数 #include<stdio.h> int main(int argc,char*argv[]) { int i; ;i<argc;i++) printf ...
- 关于boost::function与boost::bind函数的使用心得
最近开始写一个线程池,期间想用一个通用的函数模板来使得各个线程执行不同的任务,找到了Boost库中的function函数. Boost::function是一个函数包装器,也即一个函数模板,可以用来代 ...
- 子网/ip/子网掩码
IP地址由网络地址和主机地址组成 而现在IP由“子网掩码”通过子网网络地 址细分出 A,B,C类更小的网络.这种方式 实际上就是将原来的A类,B类,C类等分类 中的的主机地址部分用作子网地址,可以 将 ...
- c#写个基础的Socket通讯
晚上想写点东西,想想把我刚来公司学的Sockt通讯写上来吧.要写的简单易懂点,新人们可以借鉴下哦,用控制台写. 先得说说Socket,与TCP/UDP啥关系,一直讲什么Socket通讯,TCP通讯,都 ...
- javascript 自定义鼠标右键菜单
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...
- 使用PHP脚本来写Daemon程序
什么是Daemon进程 这又是一个有趣的概念,daemon在英语中是"精灵"的意思,就像我们经常在迪斯尼动画里见到的那些,有些会飞,有些不会,经常围着动画片的主人公转来转去,啰 ...