题意:

给你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 极角排序的更多相关文章

  1. POJ 2007 Scrambled Polygon (简单极角排序)

    题目链接 题意 : 对输入的点极角排序 思路 : 极角排序方法 #include <iostream> #include <cmath> #include <stdio. ...

  2. POJ 2007 Scrambled Polygon(简单极角排序)

    水题,根本不用凸包,就是一简单的极角排序. 叉乘<0,逆时针. #include <iostream> #include <cstdio> #include <cs ...

  3. POJ - 2007 极角排序(Java 实现)

    POJ 2007 将所有的点按逆时针输出 import java.io.*; import java.util.*; public class Main { static class Point im ...

  4. Scrambled Polygon - POJ 2007(求凸包)

    给一些点,这些点都是一个凸包上的顶点,以第一个点为起点顺时针把别的点拍排一下序列. 分析:最简单的极坐标排序了..................... 代码如下: ----------------- ...

  5. poj 1696 极角排序求最长逆时针螺旋线

    Space Ant Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4970   Accepted: 3100 Descrip ...

  6. poj 1696 极角排序(解题报告)

    #include<iostream> #include<cmath> #include<algorithm> using namespace std; double ...

  7. poj 1696(极角排序)

    Space Ant Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3924   Accepted: 2457 Descrip ...

  8. POJ 2007 Scrambled Polygon [凸包 极角排序]

    Scrambled Polygon Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 8636   Accepted: 4105 ...

  9. 简单几何(极角排序) POJ 2007 Scrambled Polygon

    题目传送门 题意:裸的对原点的极角排序,凸包貌似不行. /************************************************ * Author :Running_Time ...

随机推荐

  1. node.js中使用http-proxy-middleware请求转发给其它服务器

    var express = require('express');var proxy = require('http-proxy-middleware'); var app = express(); ...

  2. 计算机考研复试真题 a+b(大数加法)

    题目描述 实现一个加法器,使其能够输出a+b的值. 输入描述: 输入包括两个数a和b,其中a和b的位数不超过1000位. 输出描述: 可能有多组测试数据,对于每组数据, 输出a+b的值. 示例1 输入 ...

  3. 关于spring-data与elasticsearch的使用,自定义repository

    之前没有使用过spring-data,关于spring-data有很多很棒的设计,例如仅仅只需要声明一个接口就行,你甚至都不需要去实现,spring-data有内置默认的实现类,基本就上完成绝大多数对 ...

  4. kubernetes机理之调度器以及控制器

    一 了解调度器 1.1  调度器是如何将一个pod调度到节点上的 我们都已然知晓了,API服务器不会主动的去创建pod,只是拉起系统组件,这些组件订阅资源状态的通知,之后创建相应的资源,而负责调度po ...

  5. CTFshow萌新赛-web签到

    打开靶机 查看页面信息 可以看到有一个system函数 在Linux中可以使用":"隔离不同的语句 payload如下 https://5105c8b6-83aa-4993-91b ...

  6. 你这样用过DO循环吗?

    DATA: BEGIN OF text,        word1(4) TYPE c VALUE 'This',        word2(4) TYPE c VALUE 'is',         ...

  7. [Ceoi2004]Journey

    题目描述 给出N个点,及你的出发点K. 接下来N-1行描述有关边的开始点,结束点,边长.保证图中不会有环 接下来给出数字J,代表你要走多少个点. 接下来J个数字,代表你要走过的点的编号.当然你可以自己 ...

  8. Linux 安装分区设置分区大小

    一.Linux分区挂载点介绍 Linux分区挂载点介绍,推荐容量仅供参考不是绝对,跟各系统用途以及硬盘空间配额等因素实际调整: 分区类型 介绍 备注 /boot 启动分区 一般设置100M-200M, ...

  9. vue.esm.js?efeb:628 [Vue warn]: Invalid prop: type check failed for prop "defaultActive". Expected String with value "0", got Number with value 0.

    vue.esm.js?efeb:628 [Vue warn]: Invalid prop: type check failed for prop "defaultActive". ...

  10. MySQL新特性MTS

    一.MTS:多线程复制 MTS简介 在MySQL 5.6版本之前,Slave服务器上有两个线程I/O线程和SQL Thread线程.I/O线程负责接收二进制日志(Binary Log,更准确的说是二进 ...