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个点,用一条最短的绳子将所有的点都围在里面,求绳子的长度. 解题思路: 凸包的模 ...
随机推荐
- sencha touch datepicker/datepickerfield(时间选择控件)扩展(废弃 仅参考)
参考资料:https://market.sencha.com/extensions/datetimepicker 上面的扩展在2.2有些问题,参考源码重新写了一个 TimePicker: Ext.de ...
- async 与await
一. async 与await (https://segmentfault.com/a/1190000007535316) 1.async 是“异步”的简写,而 await 可以认为是 async w ...
- Python拷贝文件脚本
author : headsen chen date : 2018-12-06 17:56:58 copy_file.py #!/usr/bin/env python from sys import ...
- 基于spring-cloud的微服务(2) eureka服务提供方的注册和消费方的消费
启动Eureka注册中心之后,服务提供方就可以注册到Eureka上去(作为一个Eureka的客户端) 我们使用IDEA提供的spring initializer来新建一个springcloud项目 填 ...
- 【BZOJ4361】isn 动态规划+树状数组+容斥
[BZOJ4361]isn Description 给出一个长度为n的序列A(A1,A2...AN).如果序列A不是非降的,你必须从中删去一个数, 这一操作,直到A非降为止.求有多少种不同的操作方案, ...
- Unity3D笔记 Collect
一.输入轴 默认输入轴: Horizontal 和 Vertical被映射到w, a, s, d键和方向键 Fire1, Fire2, Fire3被分别映射到Ctrl,Option(Alt)和Comm ...
- 关于htc m9w更新后手机无限重启的解决办法
更新htc sense7.0后,手机无限重启.网上搜了一下,是和谷歌框架冲突的原因,但是机子本身没有root,删除不了gms.只能死马当活马医,把能看到google应用都给删了,就解决了. 步骤: 长 ...
- POJ-2346 Lucky tickets(线性DP)
Lucky tickets Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3298 Accepted: 2174 Descrip ...
- PAT-GPLT L1-039 - 古风排版 - [字符串输入输出]
题目链接:https://www.patest.cn/contests/gplt/L1-039 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standar ...
- SHU 414 - 字符串进制转换
题目链接:http://acmoj.shu.edu.cn/problem/414/ 很咸鱼的网上拉了个进制转换模板过来,因为数组开的太小一直WA,后来一气之下MAXN开到1e5,真是蓝瘦…… 后来实在 ...