斜率斜率斜率.........

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<map>
#include<cstring>
#include<cstdlib>
#include<vector>
using namespace std;
struct node
{
int x,y;
node(){}
node(int a,int b){x=a;y=b;}
};
int main()
{
// freopen("in","r",stdin);
vector<node>box;
map<double,int>dir;
string s;
int T,i,j,k,n,x,y,ans,t;
cin>>T;
getchar();
getchar();
for(i=0;i<T;i++)
{
box.clear();
if(i)
cout<<endl;
while(1)
{
getline(cin,s);
if(s=="\0")
break;
sscanf(s.c_str(),"%d%d",&x,&y);
box.push_back(node(x,y));
}
ans=0;
n=box.size();
for(j=0;j<n;j++)
{
dir.clear();
for(k=j+1;k<n;k++)
{
t=++dir[double(box[j].y-box[k].y)/double(box[j].x-box[k].x)];
ans=max(ans,t);
}
}
cout<<ans+1<<endl;
}
return 0;
}

Time Limit:3000MS   Memory Limit:Unknown   64bit IO Format:%lld & %llu

SubmitStatus

Description

 Lining Up 

``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!

id=21356">Input

The input begins with a single positive integer on a line by itself indicating the number of the cases following, each of them as described below. This line is followed by a blank line, and there is also a blank line between two consecutive inputs.

The input consists of N pairs of integers, where 1 < N < 700. Each pair of integers is separated by one blank and ended by a new-line character. The list of pairs is ended with an end-of-file character. No pair will occur twice.

Output

For each test case, the output must follow the description below. The outputs of two consecutive cases will be separated by a blank line.


The output consists of one integer representing the largest number of points that all lie on one line.

Sample Input

1

1 1
2 2
3 3
9 10
10 11

id=21356">Sample Output

3

Source

Root :: Competitive Programming: Increasing the Lower Bound of Programming Contests (Steven & Felix Halim) :: Chapter 7. (Computational) Geometry :: Geometry Basics ::
Lines

Root :: AOAPC I: Beginning Algorithm Contests (Rujia Liu) ::

option=com_onlinejudge&Itemid=8&category=113">
Volume 4. Algorithm Design


Root :: Competitive Programming 3: The New Lower Bound of Programming Contests (Steven & Felix Halim) :: More Advanced Topics :: Problem Decomposition ::
Two Components - Complete Search and Geometry



Root :: Competitive Programming 2: This increases the lower bound of Programming Contests. Again (Steven & Felix Halim) :: (Computational) Geometry :: Basic Geometry ::
Points and Lines

UVA270-Lining Up的更多相关文章

  1. UVA 270 Lining Up 共线点 暴力

    题意:给出几个点的位置,问一条直线最多能连过几个点. 只要枚举每两个点组成的直线,然后找直线上的点数,更新最大值即可. 我这样做过于暴力,2.7s让人心惊肉跳...应该还能继续剪枝的,同一直线找过之后 ...

  2. Lining.js - 为CSS提供 ::nth-Line 选择器功能

    在CSS中,我们使用 ::first-line 选择器来给元素第一行内容应用样式.但目前还没有像 ::nth-line.::nth-last-line 甚至 ::last-line 这样的选择器.实际 ...

  3. Lining Up(在一条直线上的最大点数目,暴力)

    Lining Up Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total ...

  4. UVA 270 Lining Up (几何 判断共线点)

     Lining Up  ``How am I ever going to solve this problem?" said the pilot. Indeed, the pilot was ...

  5. 深入解读Linux与Android的相互关系(转-lining)

    大家都知道Android是基于Linux内核的操作系统,也曾经和Linux基金会因为内核问题产生过分歧,本文将开始对Android的内核进行剖析,主要介绍Android和Linux之间的关系,后续还会 ...

  6. POJ1118 Lining Up

    快弄死我了 最后的原因是abs和fabs的区别... 说点收获:1.cmp函数返回的是int,所以不要直接返回double相减的结果2.define inf 1e9和eps 1e-93.在整数相除得到 ...

  7. poj 1118 Lining Up(水题)

    再思考一下好的方法,水过,数据太弱! 本来不想传的! #include <iostream> using namespace std; #define MAX 702 /*284K 422 ...

  8. HDU 1432 Lining Up (POJ 1118)

    枚举,枚举点 复杂度为n^3. 还能够枚举边的,n*n*log(n). POJ 1118 要推断0退出. #include<cstdio> #include<cstring> ...

  9. POJ 1118 Lining Up

    枚举,排序. 先将所有点按双关键字排序,然后枚举线的顶点$P$,剩余的点以$P$为中心进行极角排序,可以取个$gcd$,这样一样的点就排在一起了,然后统计一下更新答案. #pragma comment ...

  10. UVa 270 & POJ 1118 - Lining Up

    题目大意:给一些点,找出一条直线使尽可能多的点在这条直线上,求这条直线上点的个数. 以每一个点为原点进行枚举,求其它点的斜率,斜率相同则说明在一条直线上.对斜率排序,找出斜率连续相等的最大长度. #i ...

随机推荐

  1. python 截取指定长度汉字

    这个方法不是很好,不知道有没有更好的方法 def cut_hz(s, length): charstyle = chardet.detect(s) t = s[:length] try: unicod ...

  2. HashMap底层数据结构和算法解析

    1.Hash Map的数据结构? A:哈希表结构(链表散列:数组+链表)实现,结合数组和链表的优点.当链表长度超过8时,链表转换为红黑树. transient Node<K,V>[] ta ...

  3. CentOS7和CentOS6的主要区别

    了解一下就好 1.  文件系统的区别.CentOS6默认使用的是ext4的文件系统,而CentOS7使用的是xfs. 2.  硬盘默认调度算法不一样.CentOS6默认使用的是cfq,而CentOS7 ...

  4. 【java NIO】服务器端读写图片的一次排错经历

    上传文件方面: 一.前端 使用的是jQuery框架来上传图片,参考的是harttle大神博客:http://harttle.com/2016/07/04/jquery-file-upload.html ...

  5. Memory Allocation with COBOL

    Generally, the use of a table/array (Static Memory) is most common in COBOL modules in an applicatio ...

  6. .NET分层登陆——机房收费系统再总结

    去年的时候,我写过一篇机房收费系统登陆的总结文章,那是站在VB的基础上,直接查询数据库实现的登陆.是很初期的知识.如果想了解详情,请看VB查询数据库之登陆窗体--机房收费系统总结(一). 今天,我要换 ...

  7. linux centos下安装docker

    1.在vm中装好好centos后,更新内核 运行docker需要内核版本为3.8或者更高的版本,内核必须支持一种合适的存储驱动(Drivice Mapper.AUFS.vfs.btrfs.ZFS),默 ...

  8. [BZOJ1003](ZJOI 2006) 物流运输trans

    [题目描述] 物流公司要把一批货物从码头A运到码头B.由于货物量比较大,需要n天才能运完.货物运输过程中一般要转停好几个码头.物流公司通常会设计一条固定的运输路线,以便对整个运输过程实施严格的管理和跟 ...

  9. (转)Linux下数据段的区别(数据段、代码段、堆栈段、BSS段)

    进程(执行的程序)会占用一定数量的内存,它或是用来存放从磁盘载入的程序代码,或是存放取自用户输入的数据等等.不过进程对这些内存的管理方式因内存用途 不一而不尽相同,有些内存是事先静态分配和统一回收的, ...

  10. 最小生成树(Prime算法)

    最小生成树一·Prim算法 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 最近,小Hi很喜欢玩的一款游戏模拟城市开放出了新Mod,在这个Mod中,玩家可以拥有不止一个城 ...