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个点,用一条最短的绳子将所有的点都围在里面,求绳子的长度. 解题思路: 凸包的模 ...
随机推荐
- LeetCode 20 Valid Parentheses (括号匹配问题)
题目链接 https://leetcode.com/problems/valid-parentheses/?tab=Description Problem: 括号匹配问题. 使用栈,先进后出! ...
- Windows应急响应操作手册
查看表征异常 系统卡慢.宕机.CPU和内存占用高.网络拥塞或断网.磁盘空余空间无理由大幅度缩小等,根据以上表征,可以初步猜测系统面临的问题. windows 下查看系统基本信息 PS C:\Users ...
- Office word 2007不能另存为pdf格式的解决方法
我们在使用Office word 2007时,经常会使用到另存为 PDF 或 XPS(P),遗憾的是,很多人都找不到这个选项, 或者在安装word的时候,并没有安装该加载项,需要你在后期安装,我们来怎 ...
- JavaAgent入门
JavaAgent 是JDK 1.5 以后引入的,也可以叫做Java代理. JavaAgent 是运行在 main方法之前的拦截器,它内定的方法名叫 premain ,也就是说先执行 premain ...
- git 提示:fatal: remote origin already exists. 错误解决
今天git连接远程库的时候出现fatal: remote origin already exists. 这个错误 大概是之前连接过别的库吧 然后我们的解决办法就是删除之前的连接 1.删除git远程仓库 ...
- java.exe和javaw.exe有什么区别
- TOP100summit 2017:投资千亿成立达摩院,揭秘阿里在人工智能领域的探索
今天上午,阿里巴巴云栖大会在杭州开幕,第一条重磅消息是阿里首席技术官张建锋宣布成立达摩院,在全球各地建立实验室,3年内投入千亿在全球建立实验室.和高校建立研究所.建立全球研究中心等事务. 该院由全球实 ...
- Scala学习笔记(2)-类型注意
Scala类型注意事项: 1.Any是绝对的根,所有的其他可实例化类型均有AnyVal和AnyRef派生. 2.所有AnyVal的类型成为值类型(所有数值类型.char.Booble和Unit) 3. ...
- python3学习笔记(5)_slice
#python3 学习笔记17/07/10 # !/usr/bin/env python3 # -*- coding:utf-8 -*- #切片slice 大大简化 对于指定索引的操作 fruits ...
- Redis used_cpu_sys used_cpu_user meaning (redis info中cpu信息的含义)
Redis 中 used_cpu_sys 和 used_cpu_user含义. 在Redis的info命令输出结果中有如下四个指标,redis官网给出了下面一段解释,但是还是不明白什么意思. used ...