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. SQLite 3的中文读写

    调用sqlite3_open函数默认创建的数据库encoding=UTF-8,执行sqlite3_exec时需要将对应的字符串转换为UTF-8格式多字节字符串.比如: sqlite3* db; aut ...

  2. 更新jenkins插件,报错 Perhaps you need to run your container with "-Djava.awt.headless=true"?

    Configuring the Java environment variables vi ~/.bash_profile 在最后一行加入: export JAVA_OPTS=-Djava.awt.h ...

  3. Android按钮事件的4种写法

    经过前两篇blog的铺垫,我们今天热身一下,做个简单的例子. 目录结构还是引用上篇blog的截图. 具体实现代码: public class MainActivity extends Activity ...

  4. 【CF772D】Varying Kibibits FWT

    [CF772D]Varying Kibibits 题意:定义函数f(a,b,c...)表示将a,b,c..的10进制下的每一位拆开,分别取最小值组成的数.如f(123,321)=121,f(530,  ...

  5. 优秀的第二外语学习网站:Lang-8

    想要找native speaker帮你提高自己的写作能力么? 目前了解到的这方面最好的网站:http://lang-8.com 在这个网站上,你可以随便写一些句子或文章,然后就会有native spe ...

  6. CBV流程之View源码解析

    CBV是基于反射实现根据请求方式不同,执行不同的方法. 请求流程:view源码解析 1.urls.py :请求一定来执行视图下的as_view方法.也可以直接点击as_view()来找源码. 2.vi ...

  7. 使用SQL手动创建数据库并创建一个具有该数据库所有权限的用户

    $ mysql -u adminusername -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. ...

  8. 2.3AutoEncoder

    AutoEncoder是包含一个压缩和解压缩的过程,属于一种无监督学习的降维技术. 神经网络接受大量信息,有时候接受的数据达到上千万,可以通过压缩 提取原图片最具有代表性的信息,压缩输入的信息量,在将 ...

  9. 启用yarn日志聚集功能

    在yarn-site.xml配置文件中添加如下内容: ##开启日志聚集功能        <property>                <name>yarn.log-ag ...

  10. angularjs中的单选框绑定数据注意事项

    这里说的是angularjs 1.x 在实现单选框时,我们完全可以用html自带的<input type="radio"/>,但是配合angularjs 中的双向绑定, ...