题意:给N个点,求最多有多少个点在同一直线上

方法一:求出所有能形成的直线,两两比较,统计最多有多少条重合。

 #include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
#include<set>
#include<iostream>
using namespace std;
typedef long long int64;
const int64 maxn = ;
const int64 maxm = ;
const int64 inf = -;
struct Point64{
int x,y;
}pnt[ maxn ];
struct Node{
int64 a,b,c;
int x,y;
}tp[ maxm ]; bool s[ maxn ];
//set<int>s; void init( int n ){
for( int i=;i<n;i++ )
s[ i ] = false;
} int64 cmp( Node p1,Node p2 ){
if( p1.a!=p2.a ) return p1.a<p2.a;
else if( p1.b!=p2.b ) return p1.b<p2.b;
else return p1.c<p2.c;
} int64 gcd( int64 a,int64 b ){
int64 r;
while( b ){
r = a%b;
a = b;
b = r;
}
return a;
} void solve_gcd( int id ){
int64 Gcd = gcd( tp[ id ].a,tp[ id ].b );
Gcd = gcd( tp[ id ].c,Gcd );
tp[ id ].a /= Gcd;
tp[ id ].b /= Gcd;
tp[ id ].c /= Gcd;
} int main(){
int n;
while( scanf("%d",&n)!=EOF ){
for( int64 i=;i<n;i++ ){
cin>>pnt[i].x>>pnt[i].y;
//scanf("%lld%lld",&pnt[i].x,&pnt[i].y);
s[ i ] = false;
}
if( n==||n== ){
printf("%d\n",n);
continue;
}
int cnt = ;
for( int i=;i<n;i++ ){
for( int j=i+;j<n;j++ ){
tp[ cnt ].a = pnt[ i ].y - pnt[ j ].y;
tp[ cnt ].b = pnt[ j ].x - pnt[ i ].x;
tp[ cnt ].c = pnt[ i ].x*pnt[ j ].y - pnt[ j ].x*pnt[ i ].y;
tp[ cnt ].x = i;
tp[ cnt ].y = j;
solve_gcd( cnt );
cnt ++;
}
}
sort( tp,tp+cnt,cmp );
int64 ans = ;
int64 ans_tp = ;
int64 prea = inf;
int64 preb = inf;
int64 prec = inf;
for( int i=;i<cnt;i++ ){
if(( prea!=tp[ i ].a || preb!=tp[ i ].b || prec!=tp[ i ].c )){
ans_tp = ;
prea = tp[ i ].a;
preb = tp[ i ].b;
prec = tp[ i ].c;
memset( s,false,sizeof( s ) );
s[ tp[i].x ] = true;
s[ tp[i].y ] = true;
}
else {
if( s[ tp[i].x ]==false ) {
ans_tp ++;
s[ tp[i].x ] = true;
}
if( s[ tp[i].y ]==false ) {
ans_tp ++;
s[ tp[i].y ] = true;
}
ans = max( ans,ans_tp );
}
}
cout<<ans<<endl;
//printf("%lld\n",ans);
}
return ;
}

方法二:利用极角来排序 判断

 /*
几何
极角排序
*/
#include<algorithm>
#include<iostream>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#include<math.h>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;
typedef long long int64;
//typedef __int64 int64;
typedef pair<int64,int64> PII;
#define MP(a,b) make_pair((a),(b))
const int inf = 0x3f3f3f3f;
const double inf2 = 987654321.0;
const double pi=acos(-1.0);
const int dx[]={,-,,};
const int dy[]={,,,-};
const double eps = 1e-;
const int maxm = ;
const int maxn = ; struct Point{
double x,y;
}pnt[ maxn ],pnt2[ maxn ];
Point C; double td[ maxn ]; void initC( double x,double y ){
C.x = x;
C.y = y;
} void initP( int n ){
for( int i=;i<n;i++ ){
pnt2[ i ].x = pnt[ i ].x - C.x;
pnt2[ i ].y = pnt[ i ].y - C.y;
}
return ;
} void initTD( int n ){
for( int i=;i<n;i++ ){
td[ i ] = atan2( pnt2[ i ].y,pnt2[ i ].x );
if( td[i]< ) td[ i ] += pi;
//printf("%.2lf ",td[i]);
}
//printf("\n");
sort( td,td+n );
return ;
} double dis( Point A,Point B ){
A.x -= C.x,A.y -= C.y;
B.x -= C.x,B.y -= B.y;
return sqrt( (A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y) );
} double cmp( Point A,Point B ){
double t1 = atan2( A.y-C.y,A.x-C.x );
double t2 = atan2( B.y-C.y,B.x-C.x );
if( t1< ){
t1 = t1 + pi*2.0;
}
if( t2< ){
t2 = t2 + pi*2.0;
}
if( t1==t2 ){
return fabs( A.x )< fabs( B.x );
}
else{
return t1<t2;
}
}
/*******************************************
绕原点 以x正半轴开始逆时针旋转
角度相同 按距离原点距离比较
*******************************************/ int main(){
//freopen("in.txt","r",stdin);
int n ;
while( scanf("%d",&n)!=EOF ){
for( int i=;i<n;i++ ){
scanf("%lf%lf",&pnt[i].x,&pnt[i].y);
}
int ans = ;
double f = inf2;
for( int i=;i<n;i++ ){
initC( pnt[ i ].x,pnt[ i ].y );
initP( n );
initTD( n );
int cnt ;
double pre = inf2;
for( int j=;j<n;j++ ){
if( pre!=td[ j ] ){
pre = td[ j ];
cnt = ;
}
else {
cnt ++;
if( cnt>ans ){
ans = cnt;
f = pre;
}
//ans = max( ans,cnt+1 );
}
}
}
if( f!= ) ans ++;
printf("%d\n",max(,ans));
}
return ;
}

HDU1432+几何的更多相关文章

  1. 关于Three.js基本几何形状之SphereGeometry球体学习

    一.有关球体SphereGeometry构造函数参数说明 <1>.SphereGeometry(radius, widthSegments, heightSegments, phiStar ...

  2. 几何服务,cut功能测试

    关于几何服务 几何服务用于辅助应用程序执行各种几何计算,如缓冲区.简化.面积和长度计算以及投影.在 ArcGIS Server 管理器中启动几何服务之后,您才能够在应用程序开发过程中使用该服务. 问题 ...

  3. 几何服务,cut功能,输入要素target(修改后)内容。

    几何服务,cut功能测试,输入要素target(修改后)内容. {"displayFieldName":"","fieldAliases": ...

  4. 几何服务,cut功能,输入要素target(修改前)内容。

    几何服务,cut功能测试,输入要素target(修改前)内容. {"geometryType":"esriGeometryPolyline","geo ...

  5. 如何让你的UWP应用程序无缝调用几何作图

    有时候需要编辑一些几何图形,如三角形,圆锥曲线等,在UWP应用中加入这些几何作图功能是件费时间又很难做好的事.其实Windows 10 应用商店中已有一些专业的几何作图工具了,那么能借来一用吗?答案是 ...

  6. poj 2031Building a Space Station(几何判断+Kruskal最小生成树)

    /* 最小生成树 + 几何判断 Kruskal 球心之间的距离 - 两个球的半径 < 0 则说明是覆盖的!此时的距离按照0计算 */ #include<iostream> #incl ...

  7. NOIP2002矩形覆盖[几何DFS]

    题目描述 在平面上有 n 个点(n <= 50),每个点用一对整数坐标表示.例如:当 n=4 时,4个点的坐标分另为:p1(1,1),p2(2,2),p3(3,6),P4(0,7),见图一. 这 ...

  8. DOM 元素节点几何量与滚动几何量

    当在 Web 浏览器中查看 HTML 文档时,DOM 节点被解析,并被渲染成盒模型(如下图),有时我们需要知道一些信息,比如盒模型的大小,盒模型在浏览器中的位置等等,本文我们就来详细了解下元素节点的几 ...

  9. Get it,你离几何达人不远了!

    对于爱学几何的人,是否存在这样的困扰:没有标准的尺规工具,图形画的不标准,理解上总是出错......整天在纸上画图,浪费大把大把的时间......几何图形画的不美观,在别人面前都拿不出手,公开课上都没 ...

随机推荐

  1. .net 下载图片

    最近boss让写一个二维码的生成器,但是二维码生成后用户如果想下载二维码,这就促使我写l了 下载功能,小弟自认为技术不咋样,是个彻头彻尾的码农,本先是想用js来实现功能,但是查找了好多资料也没能实现, ...

  2. FreeMarker语法

    向原作者致敬,原文地址http://www.cnblogs.com/linjiqin/p/3388298.html FreeMarker的插值有如下两种类型:1,通用插值${expr};2,数字格式化 ...

  3. 关于 angular 小心得

    心得1: //控制器里面的代码会晚一些执行 setTimeout(function(){ //获取对象的scope var ele = document.querySelector('[ng-cont ...

  4. 当里个当,免费的HTML5连载来了《HTML5网页开发实例详解》连载(一)

    读懂<HTML5网页开发实例详解>这本书 你还在用Flash嘛?帮主早不用了 乔布斯生前在公开信“Flash之我见”中预言:像HTML 5这样在移动时代中创立的新标准,将会在移动设备上获得 ...

  5. Qt绘制异形窗体

    异形窗体即不规则窗体,一般采用png图片,一般绘制异形窗体分两步: 1.设置遮罩区 2.绘制图片   使用png图片的透明部分作为遮罩区,然后绘制图片,这样我们就看到一个只绘制了非透明部分的图形,废话 ...

  6. C# 实现HTML5服务器推送事件

    为什么需要服务器推送事件: 因为如果需要保持前台数据的实时更新例如,IM聊天,股票信息, 1.可以在客户端不断地调用服务端的方法来获得新数据,但是这样会很消耗服务器资源,导致系统变慢! 2 html5 ...

  7. C#委托的异步调用1

    本文将主要通过“同步调用”.“异步调用”.“异步回调”三个示例来讲解在用委托执行同一个“加法类”的时候的的区别和利弊. 首先,通过代码定义一个委托和下面三个示例将要调用的方法: /*添加的命名空间 u ...

  8. web页面开发笔记(不断更新)

    布局: 1.左右分列2端:使用float:left+float:right,如果一边有多列的话,另一列会对齐最下面那列.所以一般把左右各设一列,一列中再细分多行. 2.div不跟随:使用clear:b ...

  9. CentOS-6.5安装配置JDK-7|Tomcat-8

    安装说明 系统环境:centos-6.5 安装方式:rpm安装 软件:jdk-7-linux-x64.rpm 下载地址:http://www.oracle.com/technetwork/java/j ...

  10. Oracle 执行计划说明

    生成SQL的执行计划是Oracle在对SQL做硬解析时的一个非常重要的步骤,它制定出一个方案告诉Oracle在执行这条SQL时以什么样的方式访问数据:索引还是全表扫描,是Hash Join还是Nest ...