HDU1432+几何
题意:给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+几何的更多相关文章
- 关于Three.js基本几何形状之SphereGeometry球体学习
一.有关球体SphereGeometry构造函数参数说明 <1>.SphereGeometry(radius, widthSegments, heightSegments, phiStar ...
- 几何服务,cut功能测试
关于几何服务 几何服务用于辅助应用程序执行各种几何计算,如缓冲区.简化.面积和长度计算以及投影.在 ArcGIS Server 管理器中启动几何服务之后,您才能够在应用程序开发过程中使用该服务. 问题 ...
- 几何服务,cut功能,输入要素target(修改后)内容。
几何服务,cut功能测试,输入要素target(修改后)内容. {"displayFieldName":"","fieldAliases": ...
- 几何服务,cut功能,输入要素target(修改前)内容。
几何服务,cut功能测试,输入要素target(修改前)内容. {"geometryType":"esriGeometryPolyline","geo ...
- 如何让你的UWP应用程序无缝调用几何作图
有时候需要编辑一些几何图形,如三角形,圆锥曲线等,在UWP应用中加入这些几何作图功能是件费时间又很难做好的事.其实Windows 10 应用商店中已有一些专业的几何作图工具了,那么能借来一用吗?答案是 ...
- poj 2031Building a Space Station(几何判断+Kruskal最小生成树)
/* 最小生成树 + 几何判断 Kruskal 球心之间的距离 - 两个球的半径 < 0 则说明是覆盖的!此时的距离按照0计算 */ #include<iostream> #incl ...
- NOIP2002矩形覆盖[几何DFS]
题目描述 在平面上有 n 个点(n <= 50),每个点用一对整数坐标表示.例如:当 n=4 时,4个点的坐标分另为:p1(1,1),p2(2,2),p3(3,6),P4(0,7),见图一. 这 ...
- DOM 元素节点几何量与滚动几何量
当在 Web 浏览器中查看 HTML 文档时,DOM 节点被解析,并被渲染成盒模型(如下图),有时我们需要知道一些信息,比如盒模型的大小,盒模型在浏览器中的位置等等,本文我们就来详细了解下元素节点的几 ...
- Get it,你离几何达人不远了!
对于爱学几何的人,是否存在这样的困扰:没有标准的尺规工具,图形画的不标准,理解上总是出错......整天在纸上画图,浪费大把大把的时间......几何图形画的不美观,在别人面前都拿不出手,公开课上都没 ...
随机推荐
- ubuntu 更新软件源
ubuntu 更新软件源 修改文件sources.list 位于/etc/apt/sources.list,并备份原文件为sources.list.bak deb http://mirrors.163 ...
- iOS 拷贝、剪切和粘贴理论基础(转)
简介 在iPhone OS 3.0之后,用户可以在一个应用程序上拷贝文本.图像.或其它数据,然后粘贴到当前或其它应用程序的不同位置上.比如,您可以从某个电子邮件中拷贝一个地址,然后粘贴到Contact ...
- C# 微信扫码支付 回调页面
.NET版 微信扫码支付,官方推荐使用[模式二] 一.微信扫码支付模式一: 1.回调页面:官方demo中example文件下的NativeNotifyPage.aspx 2.微信回调地址:http:/ ...
- jQuery 日历控件 FullCalendar 初识
最近有个日程管理的需求,就学习了一下 FullCalendar 控件的一些基本知识,本文不是详细介绍该控件的 API 的文档,而是记录本人使用过程中的一些学习情况. 先看一下效果图 月/周/日视图 ...
- VS2010
1,vc++目录——>包含目录: Visual Studio will search for the include files referred to in your source code ...
- 使用JavaScript实现简单的输入校验
HTML页面代码: <!doctype html> <html lang="en"> <head> <meta charset=" ...
- javascript常用对象
A,window对象 window对象是浏览器模型对象的顶层对象 常用属性: screen:客户端的屏幕和显示性能的信息. history:客户端访问过的url信息 location:当前url链接的 ...
- 当前标识(NT AUTHORITY\NETWORK SERVICE)没有对“C:\WINDOWS2\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files”的写访问权限。
卸载了域控制器之后,IIS出现“当前标识(NT AUTHORITY\NETWORK SERVICE)没有对“C:\WINDOWS2\Microsoft.NET\Framework\v4.0.30319 ...
- Delphi Base64 编解码函数
Delphi 自带 Base64 编解码的单元, EncdDecd这个单元提供两套四个公开函数: 对流的编解码:procedure EncodeStream(Input, Output: TStrea ...
- 动态LINQ构建(实现等于不等于大于小于,like以及IN)
首先感谢园子里的“红烧狮子头”,他的工作是本文的基础,引文如下http://www.cnblogs.com/daviddai/archive/2013/03/09/2952087.html,本版本实现 ...