hdu1432
2016-04-07 17:58
323 查看
Lining Up
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Submit Status Practice HDU
1432
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!
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
Sample Output
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Submit Status Practice HDU
1432
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!
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
5 1 1 2 2 3 3 9 10 10 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; }
相关文章推荐
- struts2 select标签
- CFileDialog 多选文件,取得的文件路径错误BUG
- qt button以及label实现不规则图形(五种方法:使用QSS,设置Mask图片,自己画)
- iOS蓝牙4.0开发(BLE)
- LintCode-三数之和 II
- 数据分析入门(谁说菜鸟不会数据分析)
- 胖子哥的大数据之路(16):大数据采集标准-我们到底需要什么样的数据?
- 二叉树的部分操作
- 第六周项目1==分数类的雏形
- 使用OVS DPDK (by quqi99)
- 浅谈Java中final与static
- $(document).click() 在苹果手机上不能正常运行
- 《转之微信移动团队微信公众号》iOS 事件处理机制与图像渲染过程
- PHP文件处理--打开文件
- 转载一篇关于图像处理的文章,很有用,感谢作者
- 数据挖掘网上资料大全
- spark+eclipse环境搭建同时使用kmeans聚类
- 什么是按键
- C语言之malloc()函数
- Zhejiang University----Grading