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,你离几何达人不远了!
对于爱学几何的人,是否存在这样的困扰:没有标准的尺规工具,图形画的不标准,理解上总是出错......整天在纸上画图,浪费大把大把的时间......几何图形画的不美观,在别人面前都拿不出手,公开课上都没 ...
随机推荐
- ASSERT报错:error C2664: “AfxAssertFailedLine”: 不能将参数 1 从“TCHAR []”转换为“LPCSTR”
转载请注明来源:崨雁嫀筝 http://www.cnblogs.com/xuesongshu 这个错误是我在把tinyxml修改为宽字符(Unicode)版本时候遇到的问题,我首先按关键字把所有有ch ...
- JAVA TCP网络编程学习笔记
一.JAVA网络编程概述 网络应用程序,就是在已实现网络互联的不同计算机上运行的应用程序,这些程序之间可以相互交换数据.JAVA是优秀的网络编程语言,Java网络编程的类库位于java.net包中.J ...
- SQLite的简单应用
安装部署 1)进入 SQL 下载页面:http://www.sqlite.org/download.html 2)下载预编译二进制文件包. Windows 环境的如下: 下载完之后,就算部署完成.(P ...
- CSS 初体验之一
层叠样式表 (Cascading Style Sheets)”,它主要是用于定义HTML内容在浏览器内的显示样式. 1.首先先看盒装模型,如下图,平时设置的width,height是指元素内容(con ...
- js及jQuery实现checkbox的全选、反选和全不选
html代码: <label><input type="checkbox" id="all"/>全选</label> < ...
- java web 简单的分页显示
题外话:该分页显示是用 “表示层-控制层-DAO层-数据库”的设计思想实现的,有什么需要改进的地方大家提出来,共同学习进步. 思路:首先得在 DAO 对象中提供分页查询的方法,在控制层调用该方法查到指 ...
- dorado listener属性
每一个控件都有一个listener属性,可以用来定位一个服务定位表达式,通过这个表达式, 它最终可以映射为spring里面一个javaBean的一个java方法 例如设置DynaView1.view. ...
- Bitmap、CBitmap、HBITMAP以及BITMAP的相互转换
Bitmap.CBitmap.HBITMAP以及BITMAP的相互转换 构建CBitmapCBitmap bmp;bmp.LoadBitmap(ID); 构建HBITMAPHBitmap = (HBI ...
- Trie树入门及训练
什么叫Trie树? Trie树即字典树. 又称单词查找树,Trie树,是一种树形结构,是一种哈希树的变种.典型应用是用于统计,排序和保存大量的字符串(但不仅限于字符串),所以经常被搜索引擎系统用于文本 ...
- 《QQ欢乐斗地主》山寨版
使用Cocos2d-x编写,模仿<QQ欢乐斗地主>的界面实现了一个具有简单AI的单机版斗地主游戏. 游戏的详细说明请查看游戏目录下的help.txt文件. 下载地址: http://dow ...