HDU 1432 Lining Up(几何)
http://acm.hdu.edu.cn/showproblem.php?pid=1432
题目大意:
2维平面上给定n个点,求一条直线能够穿过点数最多是多少。
解题思路:
因为题目给定的n(1~700),所以枚举,时间复杂度是O(n^3),不会超时。
枚举两个点,然后判断剩下的点是否在这条直线。
AC代码:
#include<cstdio>
struct Point{
int x, y;
Point(int x = , int y = ): x(x), y(y){}
void scan(){
scanf("%d%d", &x, &y);
}
};
typedef Point Vector;
Vector operator - (Vector A, Vector B){//重载结构体减号
return Vector(A.x - B.x, A.y - B.y);
}
int cross(Vector A, Vector B){//叉乘
return A.x * B.y - A.y * B.x;
}
Point p[];
int n;
int main(){
while(~scanf("%d", &n)){
for(int i = ; i < n; ++i){
p[i].scan();
}
int best = ;//记录直线穿过最多的点个数
for(int i = ; i < n; ++i){
for(int j = i + ; j < n; ++j){
int num = ;//因为直线穿过i和j点,所以直线上已经有两个点了
for(int k = j + ; k < n; ++k){
if(!cross(p[i] - p[j], p[i] - p[k])){//判断点k在直线ij上
++num;
}
}
if(best < num){//更新最优值
best = num;
}
}
}
printf("%d\n", best);
}
return ;
}
HDU 1432 Lining Up(几何)的更多相关文章
- HDU 1432 Lining Up (POJ 1118)
枚举,枚举点 复杂度为n^3. 还能够枚举边的,n*n*log(n). POJ 1118 要推断0退出. #include<cstdio> #include<cstring> ...
- UVA 270 Lining Up (几何 判断共线点)
Lining Up ``How am I ever going to solve this problem?" said the pilot. Indeed, the pilot was ...
- HDU 4643 GSM 算术几何
当火车处在换基站的临界点时,它到某两基站的距离相等.因此换基站的位置一定在某两个基站的中垂线上, 我们预处理出任意两基站之间的中垂线,对于每次询问,求询问线段与所有中垂线的交点. 检验这些交点是否满足 ...
- hdu 5605 geometry(几何,数学)
Problem Description There is a point P at coordinate (x,y). A line goes through the point, and inter ...
- hdu 6097 Mindis(数学几何,圆心的反演点)
Mindis Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Subm ...
- hdu 1577 WisKey的眼神 (数学几何)
WisKey的眼神 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- POJ 3831 & HDU 3264 Open-air shopping malls(几何)
题目链接: POJ:id=3831" target="_blank">http://poj.org/problem?id=3831 HDU:http://acm.h ...
- HDU 1700 Points on Cycle (几何 向量旋转)
http://acm.hdu.edu.cn/showproblem.php?pid=1700 题目大意: 二维平面,一个圆的圆心在原点上.给定圆上的一点A,求另外两点B,C,B.C在圆上,并且三角形A ...
- HDU 1392 Surround the Trees(几何 凸包模板)
http://acm.hdu.edu.cn/showproblem.php?pid=1392 题目大意: 二维平面给定n个点,用一条最短的绳子将所有的点都围在里面,求绳子的长度. 解题思路: 凸包的模 ...
随机推荐
- 题目1457:非常可乐(广度优先遍历BFS)
题目链接:http://ac.jobdu.com/problem.php?pid=1457 详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus 参考代码: ...
- sencha touch 在线实战培训 第一期 第三节
2014.1.2晚上8点开的课 讲课进度比较快,好多同学反应说有些跟不上了... 呃,本期的课程是需要有一定的基础的. 建议大家多看看http://www.cnblogs.com/mlzs/p/346 ...
- Word 2013无法启用Restrict Editing解决方法
当前文档可能是Mail Merge Letter type document,MAILINGS -> Start Mail Merge -> Normal Word Document保存即 ...
- Rails: could not connect to database postgres: FATAL: Peer authentication failed for user "username"
/var/lib/pgsql/9.2/data/pg_hba.conf 打开之后找到 local all postgres/all peer 改成 local all postgres trust 保 ...
- 如何查看当前项目Laya的引擎版本
打开项目后在调试控制台输入 Laya.version
- 分布式文件系统FastDFS架构剖析
ps.本文来自于网络 一.什么是FastDfs FastDFS是一个开源的轻量级分布式文件系统,它对文件进行管理,功能包括:文件存储.文件同步.文件访问(文件上传.文件下载)等,解决了大容量存储和负载 ...
- vue之指令系统
所谓指令系统,大家可以联想咱们的cmd命令行工具,只要我输入一条正确的指令,系统就开始干活了. 在vue中,指令系统,设置一些命令之后,来操作我们的数据属性,并展示到我们的DOM上. OK,接下来我们 ...
- css实现表格的td里面的内容居中.
<td align="center" valign="middle">前一个是水平居中 后一个是垂直居中对应的css写法:<td style= ...
- openstack 部署(Q版)-----keystone认证服务安装配置
一.新建数据库及用户 CREATE DATABASE keystone; GRANT ALL PRIVILEGES ON keystone.* TO 'keystone'@'localhost' ID ...
- WCF的简单使用
WCF简单介绍 WCF(windows communication foundation)是微软推出的数据通信的统一编程模型,在WCF有四个主要的关键点: abcd Address(地址):定义服务的 ...