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 矢量 如果一条线段的端点是有次序之分的话,那么这种线段就称为 有向线段,如果 ...
随机推荐
- SpringMVC-SimpleDEMO
本博文主要将如何配置一个简单的SpringMVC的DEMO,由上一讲的SpringMVC工作流程来看,配置一个SpringMVC的步骤是简单而清晰的. 一.引入SpringMVC所需依赖 < ...
- jquery模拟点击A标签的问题
我尝试过多次用jQuery模拟用户点击a标签的功能,但都没有成功,并且困扰了很久. 先看下边的代码: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 <htm ...
- 关于hibernate插入数据到mysql数据库中文乱码问题的解决
要想解决这个问题就要找到问题的症结所在 1.首先将数据提交到action输出看action里的数据是不是中文乱码,结果很遗憾并不是这里的问题 2.设置数据库连接url: 3.打开mysql安装文件里的 ...
- 带你走进ajax(3)
使用ajax实现用户名有效性验证 需求:当用户输入完用户名时,用户可以通过页面上的按键来确认当前的用户名是否有效.如下图所示 思路:用户触发按键后可以向服务器发起http请求,将用户名提交给服务器来进 ...
- 资料:mnist.pkl.gz数据包的下载以及数据内容解释
deeplearning.net/data/mnist/mnist.pkl.gz The MNIST dataset consists of handwritten digit images and ...
- ABP官方文档翻译 1.3 模块系统
ABP模块系统 介绍 模块定义 生命周期方法 PreInitialize Initialize PostInitialize Shutdown 模块依赖 插件系统 ASP.NET Core ASP.N ...
- Cloudera Manager安装之时间服务器和时间客户端(二)
福利 => 每天都推送 欢迎大家,关注微信扫码并加入我的4个微信公众号: 大数据躺过的坑 Java从入门到架构师 人工智能躺过的坑 Java全栈大联盟 ...
- vmware 虚拟机三种网卡
转:https://blog.csdn.net/lyf_ldh/article/details/78695357 vmware为我们提供了三种网络工作模式,它们分别是:Bridged(桥接模式).NA ...
- Python3.x:常用基础语法
Python3.x:常用基础语法 1,if else语句: 不执行if内的语句,需要用:pass if i>2: #跳过不执行 pass else: print("i= %s" ...
- HashMap,HashTable,ConcorrentHashMap的线程方式
1.HashMap不是线程安全的,put,resize 2.HashTable是线程安全的,synchronized,但是效率较低 3.ConcorrentHashMap 对HashMap的一种加线程 ...