Scrambled Polygon POJ - 2007 极角排序
题意:
给你n个点,这n个点可以构成一个多边形(但是不是按顺序给你的)。原点(0,0)为起点,让你按顺序逆序输出所有点
题解:
就是凸包问题的极角排序
用double一直Wa,改了int就可以了
//原点(0,0)为起点,逆序输出多边形的点
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<math.h>
using namespace std;
const int maxn=1e3+10;
const double PI=acos(-1.0); //180度的弧度制
const double eps=1e-6;
struct Cpoint
{
int x,y;
Cpoint(){}
Cpoint(int xx,int yy):x(xx),y(yy){}
Cpoint friend operator -(Cpoint a,Cpoint b)
{
return Cpoint(a.x-b.x,a.y-b.y);
}
int friend operator ^(Cpoint a,Cpoint b)
{
return a.x*b.y-b.x*a.y;
}
bool friend operator <(Cpoint a,Cpoint b)
{
if(a.y==b.y) return a.x<b.x;
return a.y<b.y;
}
}point[maxn],init_point;
int dist(Cpoint a,Cpoint b)
{
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
int Sign(double x)
{
if(x>=-eps && x<=eps) return 0;
if(x>eps) return 1;
else return -1;
}
bool cmp(Cpoint a,Cpoint b) //积角排序
{
int s=(a-init_point)^(b-init_point); //若s>0,那么b在a点的左侧,所以a点先遍历到
if(s>0 || (s==0 && dist(a,init_point)<dist(b,init_point))) return 1;
else return 0;
}
int n;
int main()
{
int x,y;
scanf("%lf%lf",&x,&y);
init_point.x=0;
init_point.y=0;
while(~scanf("%d%d",&x,&y))
{
point[n].x=x;
point[n].y=y;
n++;
}
sort(point,point+n,cmp);
printf("(0,0)\n");
for(int i=0;i<n;++i)
{
printf("(%d,%d)\n",point[i].x,point[i].y);
}
return 0;
}
Scrambled Polygon POJ - 2007 极角排序的更多相关文章
- POJ 2007 Scrambled Polygon (简单极角排序)
题目链接 题意 : 对输入的点极角排序 思路 : 极角排序方法 #include <iostream> #include <cmath> #include <stdio. ...
- POJ 2007 Scrambled Polygon(简单极角排序)
水题,根本不用凸包,就是一简单的极角排序. 叉乘<0,逆时针. #include <iostream> #include <cstdio> #include <cs ...
- POJ - 2007 极角排序(Java 实现)
POJ 2007 将所有的点按逆时针输出 import java.io.*; import java.util.*; public class Main { static class Point im ...
- Scrambled Polygon - POJ 2007(求凸包)
给一些点,这些点都是一个凸包上的顶点,以第一个点为起点顺时针把别的点拍排一下序列. 分析:最简单的极坐标排序了..................... 代码如下: ----------------- ...
- poj 1696 极角排序求最长逆时针螺旋线
Space Ant Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4970 Accepted: 3100 Descrip ...
- poj 1696 极角排序(解题报告)
#include<iostream> #include<cmath> #include<algorithm> using namespace std; double ...
- poj 1696(极角排序)
Space Ant Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 3924 Accepted: 2457 Descrip ...
- POJ 2007 Scrambled Polygon [凸包 极角排序]
Scrambled Polygon Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 8636 Accepted: 4105 ...
- 简单几何(极角排序) POJ 2007 Scrambled Polygon
题目传送门 题意:裸的对原点的极角排序,凸包貌似不行. /************************************************ * Author :Running_Time ...
随机推荐
- db_install.rsp dbca.rsp netca.rsp 详解【转】
db_install.rsp详解 #################################################################### ## Copyright(c ...
- 算法实验5--N皇后
实验名称 回溯法解N皇后问题 实验目的 掌握回溯递归算法.迭代算法的设计与实现: 设计回溯算法求解: 分析算法的时间复杂度. 实验环境 操作系统:win 10; 编程语言:Java: 开发工具:IDE ...
- 映泰主板H100系列安装win7的各种坑
自100系列主板发布以来,windows7好像就被遗弃一样,原因就在于安装win7的时候,会出现USB设备无法使用导致无法安装的问题.主要在于Win7系统没有整合USB的XHCI驱动,而100系列芯片 ...
- freopen函数总结
函数原型: freopen(const char * __restrict__ _Filename,const char * __restrict__ _Mode,FILE * __restrict_ ...
- SAP 中session和外部断点设置的区别
1 Session Breakpoints:只在当前user session的所有main session中有效 2 External Breakpoints 在abap editor或事务SICF中 ...
- ADB 基本命令
ADB很强大,记住一些ADB命令有助于提高工作效率. 获取序列号: adb get-serialno 查看连接计算机的设备: adb devices 重启机器: adb reboot 重启到bootl ...
- 登陆的时候出现javax.xml.bind.DatatypeConverter错误
错误详情: Handler dispatch failed; nested exception is java.lang.NoClassDefFoundError: javax/xml/bind/Da ...
- (Oracle)已有数据表建立表分区—在线重定义
今天在做数据抽取的时候,发现有一张业务表数据量达到了5000W,所以就想将此表改为分区表.分区表的有点如下: 1.改善查询性能:对分区对象的查询可以仅搜索自己关心的分区,提高检索速度.2.增强可用性: ...
- cpdd 坐标:SD
updata on:2021.1.17 闲来无事继续鸽 性别:男 先鸽一会想起来再填/se
- SVN、GIT比较
Git是分布式的,完全可以不备份代码,下载下来后,在本地不必联网就可以看到所有的log,跟其他同事不会有太多的冲突,自己写的代码放在自己电脑上,一段时间后再提交.合并,也可以不用联网在本地提交 SVN ...