uva11626逆时针排序
给一个凸包,要求逆时针排序,刚开始一直因为极角排序就是逆时针的,所以一直wa,后来发现极角排序距离相同是,排的是随机的,所以要对末尾角度相同的点重新排一次
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<cassert>
#include<iomanip>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; const double g=10.0,eps=1e-;
const int N=+,maxn=+,inf=0x3f3f3f; struct point{
double x,y;
};
point p[N],s[N];
int n;
inline bool zero(double x)
{
return fabs(x)<eps;
}
double dir(point p1,point p2,point p3)
{
return (p3.x-p1.x)*(p2.y-p1.y)-(p3.y-p1.y)*(p2.x-p1.x);
}
double dis(point p1,point p2)
{
return sqrt((p2.x-p1.x)*(p2.x-p1.x)+(p2.y-p1.y)*(p2.y-p1.y));
}
bool comp(point p1,point p2)
{
double te=dir(p[],p1,p2);
if(te<)return ;
if(zero(te)&&dis(p[],p1)<dis(p[],p2))return ;
return ;
}
bool comp1(point p1,point p2)
{
return dis(p[],p1)>dis(p[],p2);
}
void Graham()
{
int pos;
double minx=inf,miny=inf;
for(int i=;i<n;i++)
{
if(p[i].x<minx||(p[i].x<minx&&p[i].y<miny))
{
minx=p[i].x;
miny=p[i].y;
pos=i;
}
}
swap(p[],p[pos]);
sort(p+,p+n,comp);
int k=n-;
while(){
if(k>=&&zero(dir(p[],p[k-],p[k])))k--;
else break;
}
sort(p+k,p+n,comp1);
cout<<n<<endl;
for(int i=;i<n;i++)
cout<<p[i].x<<" "<<p[i].y<<endl;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie();
cout<<setiosflags(ios::fixed)<<setprecision();
int t;
cin>>t;
while(t--){
cin>>n;
string c;
for(int i=;i<n;)
{
cin>>p[i].x>>p[i].y>>c;
if(c[]=='Y')i++;
else n--;
}
Graham();
}
return ;
}
/*********************
1
5
1 1 Y
1 -1 Y
0 0 N
-1 -1 Y
-1 1 Y
3
12
0 0 Y
2 0 Y
1 0 Y
3 0 Y
3 3 Y
1 3 Y
2 3 Y
3 1 Y
3 2 Y
0 1 Y
0 2 Y
0 3 Y
3
0 0 Y
1000000000 1000000000 Y
1000000000 0 Y
8
0 -2 Y
1 -1 Y
2 0 Y
1 1 Y
0 2 Y
-1 1 Y
-2 0 Y
-1 -1 Y
*********************/
uva11626逆时针排序的更多相关文章
- opencv_将图像上的4个点按逆时针排序
1:代码如下: #include "stdafx.h" #include "cxcore.h" #include "cvcam.h" #in ...
- 二维坐标系极角排序的应用(POJ1696)
Space Ant Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 3170 Accepted: 2029 Descrip ...
- poj1696(极角排序,贪心)
---恢复内容开始--- 题目链接:https://vjudge.net/problem/POJ-1696 题意:有n个点,规定起点,每次只能向左走,不能与之前的路径交叉,求最多能经过几个点. 思路: ...
- hihoCoder 1425 : What a Beautiful Lake(美丽滴湖)
hihoCoder #1425 : What a Beautiful Lake(美丽滴湖) 时间限制:1000ms 单点时限:1000ms 内存限制:256MB Description - 题目描述 ...
- 【poj3608】 Bridge Across Islands
http://poj.org/problem?id=3608 (题目链接) 题意 求两凸包间最短距离 Solution 难写难调,旋转卡壳,还真是卡死我了. 先分别选出两凸包最上点和最下点,从这两点开 ...
- opencv 61篇
(一)--安装配置.第一个程序 标签: imagebuildincludeinputpathcmd 2011-10-21 16:16 41132人阅读 评论(50) 收藏 举报 分类: OpenCV ...
- POJ 1584 A Round Peg in a Ground Hole(判断凸多边形,点到线段距离,点在多边形内)
A Round Peg in a Ground Hole Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4438 Acc ...
- POJ 1410 Intersection(判断线段交和点在矩形内)
Intersection Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9996 Accepted: 2632 Desc ...
- 计算几何基础——矢量和叉积 && 叉积、线段相交判断、凸包(转载)
转载自 http://blog.csdn.net/william001zs/article/details/6213485 矢量 如果一条线段的端点是有次序之分的话,那么这种线段就称为 有向线段,如果 ...
随机推荐
- linux文件编程----系统调用
linux中文件编程可以使用两种方法: 1).linux系统调用 2).C语言库函数 前者依赖于linux系统,后者与操作系统是独立的. 在 linux系统中,所有打开的文件也对应一个数字,这个数字由 ...
- 常用的系统架构 web服务器之iis,apache,tomcat三者之间的比较
常用的系统架构是: Linux + Apache + PHP + MySQL Linux + Apache + Java (WebSphere) + Oracle Windows Server 200 ...
- 爬虫——请求库之requests
阅读目录 一 介绍 二 基于GET请求 三 基于POST请求 四 响应Response 五 高级用法 一 介绍 #介绍:使用requests可以模拟浏览器的请求,比起之前用到的urllib,reque ...
- phpMyAdmin的安装配置
找到$cfg['blowfish_secret'] = '',将其值改为你自己想要的任意字符,如$cfg['blowfish_secret'] = 'owndownd': 找到$cfg['Server ...
- Linux系统——源码编译安装
记得要先去把httpd-2.2.9.tar.gz通过xftp进行文件传输第一步:yum仓库下安装编译环境的支持程序 #yum -y install gcc gcc-c++ make 第二步:将源码包h ...
- Winter-1-B Sum 解题报告及测试数据
Time Limit:500MS Memory Limit:32768KB Description Hey, welcome to HDOJ(Hangzhou Dianzi University O ...
- [Python]返回函数,装饰器拾遗
def lazy_print(*args): def pr(): print(args) return pr 当我们调用lazy_print()时,返回的并不是求和结果,而是求和函数: >> ...
- Lucene.Net 3.0.3如何从TokenStream中获取token对象
Lucene.Net最高版本为3.0.3,并且apache已经不再提供Lucene.Net的更新,没仔细研究过Lucene.Net的所有版本,Lucene.Net3.0.3遍历TokenStream获 ...
- Spring编码过滤器:解决中文乱码
Spring编码过滤器:解决中文乱码 针对问题: 前台JSP页面和JAVA代码中使用了不同的字符集进行编码的时候就会出现表单提交的数据或者上传/下载中文名称文件出现乱码的问题: 解决方案: web.x ...
- Fiddler4工具配置及调试手机和PC端浏览器
Fiddler最大的用处: 模拟请求.修改请求.手机应用调试 Fiddler最新版本 下载地址: http://www.telerik.com/download/fiddler Fiddler 想要监 ...