hdu1432
来源:互联网 发布:路由器域名重定向设置 编辑:程序博客网 时间:2024/04/30 06:25
Lining Up
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64uDescription
``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
解体思路:利用向量共线定理,暴力枚举。
代码如下:
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int x[710],y[710];int main(){int n,i,j,k,sum,ans;while(scanf("%d",&n)!=EOF){ans=0;sum=0;for(i=1;i<=n;i++)scanf("%d%d",&x[i],&y[i]); for(i=1;i<=n;i++){//i点为公共端点 for(j=i+1;j<=n;j++){ ans=0; for(k=j+1;k<=n;k++){ if((x[j]-x[i])*(y[k]-y[i])-(x[k]-x[i])*(y[j]-y[i])==0) ans++; } sum=sum>ans?sum:ans; } } printf("%d\n",sum+2); }return 0;}
0 0
- hdu1432
- POJ1118 HDU1432 Lining Up
- hdu1432 Lining Up --判断点在一条线上的个数
- 解决listview与scrollview结合使用时出现的问题
- requirejs加载css
- 第六周项目1==分数类的雏形
- 基于halcon工业图像处理——初学
- 二叉树的部分操作
- hdu1432
- 文章标题
- Implementing a Neural Network from Scratch in Python – An Introduction
- ceshi
- 数据分析入门(谁说菜鸟不会数据分析)
- Android webview使用详解
- poj 3669 meteor shower
- 数据库sql
- struts2 select标签