HDU 1432 Lining Up(几何)

http://acm.hdu.edu.cn/showproblem.php?pid=1432

题目大意:

  2维平面上给定n个点,求一条直线能够穿过点数最多是多少。

解题思路:

  因为题目给定的n(1~700),所以枚举,时间复杂度是O(n^3),不会超时。

枚举两个点,然后判断剩下的点是否在这条直线。

AC代码:

 1 #include<cstdio>
 2
 3 struct Point{
 4     int x, y;
 5
 6     Point(int x = 0, int y = 0): x(x), y(y){}
 7
 8     void scan(){
 9         scanf("%d%d", &x, &y);
10     }
11 };
12
13 typedef Point Vector;
14
15 Vector operator - (Vector A, Vector B){//重载结构体减号
16     return Vector(A.x - B.x, A.y - B.y);
17 }
18
19 int cross(Vector A, Vector B){//叉乘
20     return A.x * B.y - A.y * B.x;
21 }
22
23 Point p[700];
24 int n;
25
26 int main(){
27     while(~scanf("%d", &n)){
28         for(int i = 0; i < n; ++i){
29             p[i].scan();
30         }
31
32         int best = 0;//记录直线穿过最多的点个数
33         for(int i = 0; i < n; ++i){
34             for(int j = i + 1; j < n; ++j){
35                 int num = 2;//因为直线穿过i和j点,所以直线上已经有两个点了
36                 for(int k = j + 1; k < n; ++k){
37                     if(!cross(p[i] - p[j], p[i] - p[k])){//判断点k在直线ij上
38                         ++num;
39                     }
40                 }
41                 if(best < num){//更新最优值
42                     best = num;
43                 }
44             }
45         }
46         printf("%d\n", best);
47     }
48     return 0;
49 }
时间: 2025-01-01 10:23:03

HDU 1432 Lining Up(几何)的相关文章

POJ 1018 &amp; HDU 1432 Lining Up 【简单几何】

Lining Up Time Limit: 2000MS   Memory Limit: 32768K Total Submissions: 24786   Accepted: 7767 Description "How am I ever going to solve this problem?" said the pilot. Indeed, the pilot was not facing an easy task. She had to drop packages at spe

HDU 1432 Lining Up (POJ 1118)

枚举,枚举点 复杂度为n^3. 还可以枚举边的,n*n*log(n). POJ 1118 要判断0退出. #include<cstdio> #include<cstring> #include<string> #include<queue> #include<algorithm> #include<map> #include<stack> #include<iostream> #include<list&

HDU 4793 Collision + HDU 4798 Skycity 简单几何

HDU 4793 链接:http://acm.hdu.edu.cn/showproblem.php?pid=4793 题意:给一个以(0,0)为圆心半径为R的圆形区域,中间放着一个(0,0)为圆心半径为Rm的圆盘,在坐标(x,y)处(严格在圆形区域外)放着一枚半径为r的硬币,运动方向和速度为(vx,vy),在运动中碰到圆盘时,会按碰撞问题反弹(圆盘是固定不动的),问硬币会在圆形区域里呆多长时间(硬币只要有一点点在圆形区域里就记为硬币在圆形区域内). 思路:首先先计算出硬币在移动过程中如果不与圆盘

Hdoj 1432 Lining Up 【叉积】

Lining Up Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1094    Accepted Submission(s): 307 Problem Description ``How am I ever going to solve this problem?" said the pilot. Indeed, the pilot

第六场 hdu 6097 Mindis (几何)

http://acm.hdu.edu.cn/showproblem.php?pid=6097 题目大意:有个圆,圆内有两个点P,Q,已知PO=QO,求圆上一点D,使得PD+QD最小 解题思路:官方题解 找着题解一步步想的,代码中有详细的解释 AC代码: 1 #include <iostream> 2 #include <bits/stdc++.h> 3 using namespace std; 4 const double eps=1e-8; 5 void work() 6 { 7

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

Mindis Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 2787    Accepted Submission(s): 555Special Judge Problem Description The center coordinate of the circle C is O, the coordinate of O is (0,

HDU 4709 Herding 几何题解

求所有点组成的三角形最小的面积,0除外. 本题就枚举所有可以组成的三角形,然后保存最小的就是答案了,因为数据量很少. 复习一下如何求三角形面积.最简便的方法就是向量叉乘的知识了. 而且是二维向量叉乘P1(ax, ay), P2(bx, by),公式为:|P1 X P2| = abs(ax*by - ay*bx) 三角形面积就是|P1 X P2| / 2; 本题也是float过不了,换成double就可以过了. const int MAX_N = 101; struct VertexPoint {

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

WisKey的眼神 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2059    Accepted Submission(s): 625 Problem Description WisKey的眼镜有500多度,所以眼神不大好,而且他有个习惯,就是走路喜欢看着地(不是为了拣钱哦^_^),所以大家下次碰见他的时候最好主动打下招呼,呵呵.但是

hdu 1115 Lifting the Stone (数学几何)

Lifting the Stone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 5203    Accepted Submission(s): 2155 Problem Description There are many secret openings in the floor which are covered by a big