Scrambled Polygon POJ - 2007(极角排序)

Scrambled Polygon

POJ - 2007

题意:

思路:其实就是将(0,0)这个点按照极角排序,其他点对于(0,0)来排序,将排序后输出就行,注意输入不定

 1 //
 2 // Created by HJYL on 2020/1/17.
 3 //
 4 #include<iostream>
 5 #include<cstring>
 6 #include<cstdio>
 7 #include<cmath>
 8 #include<algorithm>
 9 using namespace std;
10 const double eps=1e8;
11 int dcmp(double x)
12 {
13     if(fabs(x)<eps)
14         return 0;
15     return x<0?-1:1;
16 }
17 struct Point{
18     int x,y;
19     int id;
20     Point(){}
21     Point(int id,double x,double y):id(id),x(x),y(y){}
22 }initial;//以当前点来求最外凸包
23
24 typedef Point Vector;
25
26 Vector operator-(Point A,Point B)
27 {
28     return Vector(-1,A.x-B.x,A.y-B.y);
29 }
30 //叉积
31 double Cross(Vector A,Vector B)
32 {
33     return A.x*B.y-A.y*B.x;
34 }
35
36 double Len(Point A,Point B)
37 {
38     return (A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y);
39 }
40
41 //极角排序
42 bool cmp(const Point& A,const Point& B)
43 {
44     double t=Cross(A-initial,B-initial);
45     if(t>0)//叉积大于0,B在A的左边,A在外凸包上
46         return true;
47     else if(t<0)
48         return false;
49     else
50         return Len(A,initial)<Len(B,initial);//极角相同采用最近的点
51
52 }
53
54 const int maxn=100;
55 int main()
56 {
57     Point p[maxn];
58     int x,y;
59     while(~scanf("%d%d",&x,&y))
60     {
61         int  num=0;
62         initial=Point(0,0,0);
63         while(~scanf("%d%d",&p[num].x,&p[num].y)){
64             num++;
65         }
66         printf("(0,0)\n");
67         for(int i=0;i<num;i++)
68         {
69             sort(p,p+num,cmp);
70             printf("(%d,%d)\n",p[i].x,p[i].y);
71         }
72     }
73     return 0;
74 }

原文地址:https://www.cnblogs.com/Vampire6/p/12241198.html

时间: 2024-10-13 00:55:21

Scrambled Polygon POJ - 2007(极角排序)的相关文章

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

水题,根本不用凸包,就是一简单的极角排序. 叉乘<0,逆时针. #include <iostream> #include <cstdio> #include <cstring> #include <string> #include <algorithm> using namespace std; const int maxn=55; struct point { double x,y; } p[maxn]; double cross(poi

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

题目链接 题意 : 对输入的点极角排序 思路 : 极角排序方法 #include <iostream> #include <cmath> #include <stdio.h> #include <algorithm> using namespace std; struct point { double x,y; }p[50],pp; double cross(point a,point b,point c) { return (a.x-c.x)*(b.y-c

[POJ2007]Scrambled Polygon(计算几何 极角排序)

题目链接:http://poj.org/problem?id=2007 题意:给出凸包和起点,逆序输出. 极角排序可以用反三角函数求出角度,按照角度排序.也可以用叉乘来做.注意题目说给定第一个数据是0,0,这是凸包的起点,数据中有在x轴负半轴的数据,所以排序的时候0,0要跳过.只排1~n-1个坐标. 1 #include <algorithm> 2 #include <iostream> 3 #include <iomanip> 4 #include <cstri

POJ 2007 Scrambled Polygon(计算几何 叉积排序啊)

题目链接:http://poj.org/problem?id=2007 Description A closed polygon is a figure bounded by a finite number of line segments. The intersections of the bounding line segments are called the vertices of the polygon. When one starts at any vertex of a close

poj 1696(极角排序)

Space Ant Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3924   Accepted: 2457 Description The most exciting space discovery occurred at the end of the 20th century. In 1999, scientists traced down an ant-like creature in the planet Y19

poj 2007 Scrambled Polygon 极角排序

1 /** 2 极角排序输出,,, 3 主要atan2(y,x) 容易失精度,,用 4 bool cmp(point a,point b){ 5 if(cross(a-tmp,b-tmp)>0) 6 return 1; 7 if(cross(a-tmp,b-tmp)==0) 8 return length(a-tmp)<length(b-tmp); 9 return 0; 10 } 11 **/ 12 #include <iostream> 13 #include <algo

poj 2007 Scrambled Polygon(极角排序)

http://poj.org/problem?id=2007 Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 6701   Accepted: 3185 Description A closed polygon is a figure bounded by a finite number of line segments. The intersections of the bounding line segments ar

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

题目传送门 题意:裸的对原点的极角排序,凸包貌似不行. /************************************************ * Author :Running_Time * Created Time :2015/11/3 星期二 14:46:47 * File Name :POJ_2007.cpp ************************************************/ #include <cstdio> #include <al

POJ 2007 Scrambled Polygon 极角序 水

LINK 题意:给出一个简单多边形,按极角序输出其坐标. 思路:水题.对任意两点求叉积正负判断相对位置,为0则按长度排序 /** @Date : 2017-07-13 16:46:17 * @FileName: POJ 2007 凸包极角序.cpp * @Platform: Windows * @Author : Lweleth ([email protected]) * @Link : https://github.com/ * @Version : $Id$ */ #include <std