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(几何)的更多相关文章

  1. HDU 1432 Lining Up (POJ 1118)

    枚举,枚举点 复杂度为n^3. 还能够枚举边的,n*n*log(n). POJ 1118 要推断0退出. #include<cstdio> #include<cstring> ...

  2. UVA 270 Lining Up (几何 判断共线点)

     Lining Up  ``How am I ever going to solve this problem?" said the pilot. Indeed, the pilot was ...

  3. HDU 4643 GSM 算术几何

    当火车处在换基站的临界点时,它到某两基站的距离相等.因此换基站的位置一定在某两个基站的中垂线上, 我们预处理出任意两基站之间的中垂线,对于每次询问,求询问线段与所有中垂线的交点. 检验这些交点是否满足 ...

  4. hdu 5605 geometry(几何,数学)

    Problem Description There is a point P at coordinate (x,y). A line goes through the point, and inter ...

  5. hdu 6097 Mindis(数学几何,圆心的反演点)

    Mindis Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Subm ...

  6. hdu 1577 WisKey的眼神 (数学几何)

    WisKey的眼神 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  7. POJ 3831 &amp; HDU 3264 Open-air shopping malls(几何)

    题目链接: POJ:id=3831" target="_blank">http://poj.org/problem?id=3831 HDU:http://acm.h ...

  8. HDU 1700 Points on Cycle (几何 向量旋转)

    http://acm.hdu.edu.cn/showproblem.php?pid=1700 题目大意: 二维平面,一个圆的圆心在原点上.给定圆上的一点A,求另外两点B,C,B.C在圆上,并且三角形A ...

  9. HDU 1392 Surround the Trees(几何 凸包模板)

    http://acm.hdu.edu.cn/showproblem.php?pid=1392 题目大意: 二维平面给定n个点,用一条最短的绳子将所有的点都围在里面,求绳子的长度. 解题思路: 凸包的模 ...

随机推荐

  1. Elasticsearch学习之快速入门案例

    1. document数据格式 面向文档的搜索分析引擎 (1)应用系统的数据结构都是面向对象的,复杂的(2)对象数据存储到数据库中,只能拆解开来,变为扁平的多张表,每次查询的时候还得还原回对象格式,相 ...

  2. 在 NHibernate 中一切必须是 Virtual 的吗?

    原文地址:Must Everything Be Virtual With NHibernate? 老赵在博文中 我对NHibernate的感受(2):何必到处都virtual 提到这篇文章,顺便翻译一 ...

  3. [MySQL]修改root密码的4种方法(以windows为例)

    方法1: 用SET PASSWORD命令 首先登录MySQL. 格式:mysql> set password for 用户名@localhost = password('新密码'); 例子:my ...

  4. POJ-2029 Get Many Persimmon Trees(动态规划)

    Get Many Persimmon Trees Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 3987 Accepted: 2 ...

  5. POJ3660 Cow Contest【最短路-floyd】

    N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming contest. As we ...

  6. opencv学习笔记——时间计算函数getTickCount()和getTickFrequency()

    cv::getTickCount()可以用来测量一段代码的运行时间,这个函数返回从上次开机算起的时钟周期数. 由于我们需要的是某个代码段运行的毫秒数,因此还需要另一个函数cv::getTickFreq ...

  7. c++从文件中读取一行数据并保存在数组中

    从txt文本中读取数据存入数组中 #include <iostream> #include <fstream> #include <string> #include ...

  8. SQL Fundamentals: Using Single-Row Functions to Customize Output使用单行函数自定义输出

    SQL Fundamentals || Oracle SQL语言 DUAL is a public table that you can use to view results from functi ...

  9. TACOTRON:端到端的语音合成

    tacotron主要是将文本转化为语音,采用的结构为基于encoder-decoder的Seq2Seq的结构.其中还引入了注意机制(attention mechanism).在对模型的结构进行介绍之前 ...

  10. 洛谷P4289 移动玩具 HAOI2008 搜索+状压

    正解:状压 解题报告: 先,放下传送门QwQ 说真的我jio得这题不管是思路还是实现上,都还是有一定难度的?然后就看到神仙hl博客里一句"太水了不讲了"就过掉了,,,好的趴太强辽Q ...