hdoj--1432--Lining Up(暴力模拟)
来源:互联网 发布:神圣的战争 知乎 编辑:程序博客网 时间:2024/05/06 11:51
Lining Up
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1274 Accepted Submission(s): 366
Problem 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 specific points scattered in a dangerous area. Furthermore, the pilot could only fly over the area once in a straight line, and she had to fly over as many points as possible. All points were given by means of integer coordinates in a two-dimensional space. The pilot wanted to know the largest number of points from the given set that all lie on one line. Can you write a program that calculates this number?
Your program has to be efficient!
Indeed, the pilot was not facing an easy task. She had to drop packages at specific points scattered in a dangerous area. Furthermore, the pilot could only fly over the area once in a straight line, and she had to fly over as many points as possible. All points were given by means of integer coordinates in a two-dimensional space. The pilot wanted to know the largest number of points from the given set that all lie on one line. Can you write a program that calculates this number?
Your program has to be efficient!
Input
The input consists of multiple test cases, and each case begins with a single positive integer on a line by itself indicating the number of points, followed by N pairs of integers, where 1 < N < 700. Each pair of integers is separated by one blank and ended by a new-line character. No pair will occur twice in one test case.
Output
For each test case, the output consists of one integer representing the largest number of points that all lie on one line, one line per case.
Sample Input
51 12 23 39 1010 11
Sample Output
3
Source
ACM暑期集训队练习赛(四)
Recommend
lcy | We have carefully selected several similar problems for you: 1454 1374 2297 1392 1798
题意:n个点,然后求同一条线上数量最多的点的个数,,,,就是那样吧,求点的个数
思路:先对点排序,求出所有直线的k还有b,然后寻找最多的相同的k,b个数,然后去重
#include<stdio.h>#include<string.h>#include<math.h>#include<algorithm>#include<iostream>#define INF 0x3f3f3f3f#define ull unsigned long long#define ll long long#define IN __int64#define N 710#define M 100000000using namespace std;struct zz{ int x; int y;}p[N];int cmp(zz a,zz b){ if(a.x==b.x) return a.y<b.y; return a.x<b.x;}struct ss{ double k; double b;}pp[N*N];bool cmpp(ss a,ss b){ if(a.k==b.k) return a.b<b.b; return a.k<b.k;}int main(){ int n,i,j,k; while(scanf("%d",&n)!=EOF) { for(i=0;i<n;i++) scanf("%d%d",&p[i].x,&p[i].y); sort(p,p+n,cmp); int kk=0; int km=0; for(i=0;i<n-1;i++) { for(j=i+1;j<n;j++) { int x=p[j].x-p[i].x; int y=p[j].y-p[i].y; pp[kk].k=y*1.0/x; pp[kk].b=p[i].y-pp[kk].k*p[i].x; kk++; } } sort(pp,pp+kk,cmpp); int m=1,mm=1; ss f=pp[0]; for(i=1;i<kk;i++) { if(fabs(pp[i].k-f.k)<1e-6&&fabs(f.b-pp[i].b)<1e-6) { m++; mm=max(mm,m); } else { f=pp[i]; m=1; } } if(n==1) printf("1\n"); else if(n==2) printf("2\n"); else { if(mm==3) printf("%d\n",mm); else { mm*=2; for(int i=1;i<=n;i++) { if(i*(i+1)==mm) { printf("%d\n",i+1); break; } } } } } return 0;}
0 0
- hdoj--1432--Lining Up(暴力模拟)
- hdoj 1432 Lining Up
- hdoj 1432 Lining Up
- uva270 - Lining Up(暴力)
- Hdoj 1432 Lining Up 【叉积】
- hdoj 1432 Lining Up 【思维】
- uva 270 Lining Up(暴力+ 几何)
- uva 270 Lining Up(暴力)
- poj 1118 Lining Up (暴力)
- hdoj Lining Up 1432 (数学)直线过最多点问题
- hdoj 1432 && poj 2606 Lining Up (多点共线)
- [排序&&模拟]Lining Up uva270
- HDU 1432 Lining Up (POJ 1118)
- HDU:1432 Lining Up(数学)
- hdu 1432 Lining Up
- Hdu 1432-Lining Up
- HDU 1432 Lining Up
- UVA 270 Lining Up 共线点 暴力
- Jenkins插件之AnsiColor
- 【codevs 2981】题解
- POJ 2429 GCD & LCM Inverse(Pollard_rho法质因数分解)
- JavaScript 防篡改对象
- LeetCode 9 Palindrome Number
- hdoj--1432--Lining Up(暴力模拟)
- QCheckBox类
- 隐藏listView的滚动条
- linux下的网络模型
- java实现图的最短路径(SP)的贝尔曼福特(Bellman-Ford)算法
- poj1039 pipe 计算几何
- 学习Python
- kvm
- 坚持写博客