hdoj 1432 && poj 2606 Lining Up (多点共线)
2016-04-12 16:37
295 查看
Lining Up
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1326 Accepted Submission(s): 376
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!
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 <iostream> #include <cstdio> #include <algorithm> using namespace std; struct Node { int x; int y; }a[1100]; int main() { int n,ans,max; while(~scanf("%d",&n)) { for(int i=0;i<n;i++) { scanf("%d%d",&a[i].x,&a[i].y); } max=0; for(int i=0;i<n;i++) { for(int j=i+1;j<n;j++) { ans=0; for(int k=j+1;k<n;k++) { if((a[j].x-a[i].x)*(a[k].y-a[j].y)-(a[k].x-a[j].x)*(a[j].y-a[i].y)==0) ans++; } if(max<ans) max=ans; } } printf("%d\n",max+2); } return 0; }
Rabbit hunt(相同题目)
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 7915 | Accepted: 3942 |
7 122
8 139
9 156
10 173
11 190
-100 1
Sample Output
5
相关文章推荐
- SELinux Redhat url
- Leetcode no. 330
- Maven pom.xml 配置详解
- 2.快速部署MySQL主从复制
- 4.MySQL 主主(m-m) 同步生产库标准同步操作实施流程
- ceph 块设备
- expect交互式脚本
- 图论复习笔记
- 53. Maximum Subarray
- Computer Hardware ID(CHID)及驱动推送
- Oracle内存结构
- Java 设计模式--策略模式
- android(NDK+JNI)---JNI字符串参数传递与返回值
- 安卓-获取图片/视频的缩略图
- Splunk公司在线笔试题(2016.4.12)
- 求数列的最大子段和的两种方法(包括时间复杂度为线性时间的算法)
- js中的call替代继承问题
- 关于 Android 混淆的一些心得
- jsoup
- 常用正则表达式