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 ...
随机推荐
- 剑指Offer-连续子数组中的最大和
题目 输入一个整型数组,数组里有正数也有负数.数组中的一个或连续多个整数组成一个子数组.求所有子数组的和的最大值.要求时间复杂度为 O(n). 输入 [1,-2,3,10,-4,7,2,-5] 返回值 ...
- Linux性能相关命令
Linux性能相关命令 目录 Linux性能相关命令 1. 查看硬盘相关信息 2. 查看CPU相关信息 3. 查看内存相关信息 4. 查看进程运行的信息 1. 查看硬盘相关信息 cat /proc/s ...
- 透过现象看本质:Java类动态加载和热替换
摘要:本文主要介绍类加载器.自定义类加载器及类的加载和卸载等内容,并举例介绍了Java类的热替换. 最近,遇到了两个和Java类的加载和卸载相关的问题: 1) 是一道关于Java的判断题:一个类被首次 ...
- MySQL数据库基础知识及优化
MySQL数据库基础知识及优化必会的知识点,你掌握了多少? 推荐阅读: 这些必会的计算机网络知识点你都掌握了吗 关于数据库事务和锁的必会知识点,你掌握了多少? 关于数据库索引,必须掌握的知识点 目录 ...
- redis 主从复制(一主两从)
一.环境基本信息 系统 centos7 版本 redis 5.0.7 只用了一台机器,ip:192.168.64.123 master端口 6379,从机 端口 6380.6381 二.redis目录 ...
- LuoguP5075 [JSOI2012]分零食
题意 有\(A\)个人,\(m\)个糖,你可以选择一个\(k\),使第\(1\)$k$个人每个人至少得到一个糖,并且第$k+1$\(A\)个人都得不到糖.\(m\)个糖必须给完.对于每个方案都有一个欢 ...
- USB充电限流IC,可调到4.8A,输入 6V关闭
随着手机充电电流的提升,和设备的多样化,USB限流芯片就随着需求的增加而越来越多,同时为了更好的保护电子设备,需要进行一路或者多路的负载进行限流. 一般说明 PW1503,PW1502是超低RDS(O ...
- 02. struts2中Action名称的搜索顺序
搜索顺序 获得请求路径的URI,例如URL为:http://localhost:8080/struts2/path1/path2/path3/student.action 首先寻找namespace为 ...
- NIO非阻塞网络编程原理
NIO非阻塞网络编程原理 1.NIO基本介绍 Java NIO 全称 java non-blocking IO,是指 JDK 提供的新 API.从 JDK1.4 开始,Java 提供了一系列改进的 输 ...
- 标准PE头属性说明