【kuangbin专题】计算几何基础(极角相关)



【POJ 1696】 Space Ants

【题目大意】

给定多个点,对他们按照下面的规则排序,每个都在前一个点组成的左边,并且连线不相交(典型如图)

【题目分析】

不断进行极角排序,不断选取一定区域内最符合要求的解

【代码】

 1 #include<cstdio>
 2 #include<iostream>
 3 #include<algorithm>
 4 #define ll double
 5 using namespace std;
 6 const double eps  = 1e-9;
 7 const int    MAXN = 1010;
 8 int sgn(ll x)
 9 {
10     if (x > eps) return  1;
11     if (x < -eps)return -1;
12     return 0;
13 }
14 struct P
15 {
16     ll   x, y ;
17     int  index;
18     P() {};
19     P(double a, double b) :x(a), y(b) {}
20     P      operator -(P a) { return P(x - a.x, y - a.y); }
21     double operator *(P a) { return x * a.x + y * a.y  ; }
22     double operator ^(P a) { return x * a.y - y * a.x  ; }
23 };
24 struct L
25 {
26     P s, t;
27     L() {}
28     L(P a, P b) :s(a), t(b) {}
29 };
30 double dis(P a, P b)
31 {
32     return (b - a)*(b - a);
33 }
34 P   p[MAXN];
35 int pos;
36 bool cmp(P a, P b)
37 {
38     int tmp = sgn((a - p[pos]) ^ (b - p[pos]));
39     if (tmp == 0)    return dis(b, p[pos]) > dis(a, p[pos]);
40     if (tmp <  0)   return false;
41                     return true;
42 }
43 int main()
44 {
45     int T;
46     scanf("%d", &T);
47     while (T--)
48     {
49         int n;
50         scanf("%d", &n);
51         for (int i = 1; i <= n; i++)
52         {
53             scanf("%d %lf %lf", &p[i].index, &p[i].x, &p[i].y);
54             if ((p[i].y == p[1].y && p[i].x < p[1].x )||(p[i].y<p[1].y))
55                 swap(p[1], p[i]);
56         }
57         pos = 1;
58         for (int i = 2; i <= n; i++)
59         {
60             sort(p+i,p+n+1,cmp);
61             pos++;
62         }
63         printf("%d ", n);
64         for (int i = 1; i <= n; i++)
65         {
66             printf("%d", p[i].index);
67             if (i != n)
68                 printf(" ");
69             else
70                 printf("\n");
71         }
72     }
73     return 0;
74 }



【kuangbin专题】计算几何基础(极角相关)

原文地址:https://www.cnblogs.com/rentu/p/11631727.html

时间: 2024-08-27 02:56:57

【kuangbin专题】计算几何基础(极角相关)的相关文章

Endnote专题之--output style相关问题

Endnote专题之--output style相关问题 1. 打开output style, Edit--->Output Styles--->选择要编辑的某个style模板,如下面的Edit"计算机学报-JCST", 通常文献格式模板可以在已有内置模板的基础上进行修改, EndNote模板均可以从EndNote官网下载: http://endnote.com/support/enstyles.asp 2.设置output style的样式: 包括两部分,一部分为论文正文

nyis oj 68 三点顺序 (计算几何基础)

三点顺序 时间限制:1000 ms  |  内存限制:65535 KB 难度:3 描写叙述 如今给你不共线的三个点A,B,C的坐标,它们一定能组成一个三角形,如今让你推断A,B,C是顺时针给出的还是逆时针给出的? 如: 图1:顺时针给出 图2:逆时针给出 <图1>                   <图2> 输入 每行是一组測试数据,有6个整数x1,y1,x2,y2,x3,y3分别表示A,B,C三个点的横纵坐标.(坐标值都在0到10000之间) 输入0 0 0 0 0 0表示输入

计算几何基础——【点积和叉积的用处】

计算几何是算法竞赛的一大块,而叉积是计算机和的基础. 首先叉积是计算说向量之间的叉积,那么我们可以这样定义向量,以及向量的运算符重载. struct Point { double x,y; Point(double x=0,double y=0):x(x),y(y) {} }; typedef Point Vector; Vector operator + (Vector A,Vector B) { return Vector(A.x+B.x,A.y+B.y); } Vector operato

kuangbin专题四 : 最短路 I 题 Arbitrage

kuangbin专题四 : 最短路 I 题  Arbitrage POJ 2240 Arbitrage is the use of discrepancies in currency exchange rates to transform one unit of a currency into more than one unit of the same currency. For example, suppose that 1 US Dollar buys 0.5 British pound,

kuangbin专题专题四 Til the Cows Come Home POJ - 2387

题目链接:https://vjudge.net/problem/POJ-2387 题意:从编号为n的城市到编号为1的城市的最短路. 思路:dijkstra模板题,直接套板子,代码中我会带点注释给初学者看. 1 #include <iostream> 2 #include <cstring> 3 #include <algorithm> 4 #include <cstdio> 5 #include <string> 6 using namespac

知识点 - 计算几何基础

知识点 - 计算几何基础 讲义 点 我们把点 \(\mathbf r\) 看成从 \(\mathbf 0\) 到 \(\mathbf r\)的向量 \(\vec{\mathbf r}\) #define ftype long double struct point2d { ftype x, y; point2d() {} point2d(ftype x, ftype y): x(x), y(y) {} point2d& operator+=(const point2d &t) { x +=

kuangbin专题 专题九 连通图 HDU 4738 Caocao&#39;s Bridges

题目链接:https://vjudge.net/problem/HDU-4738 题目:tarjan求桥,坑点: 题目说是分岛任务...如果所有岛之间没有完全连通,就不需要执行任务了...答案直接是0... 桥上可能没人,但是,炸弹需要一个人去送,所以至少1个人. 1 #include <iostream> 2 #include <cstdio> 3 #include <algorithm> 4 using namespace std; 5 6 const int N

计算几何及其应用——计算几何基础

写在前面:当时开计算几何这个专题神奇的从解析几何开始了,然后最近发现<计算几何及应用(金博)>这本书前面那章忽略掉了一些重要的东西比如说点定位.半平面相交之类的东西,恰好还有一些和计算几何扯上边但是不需要算法的简单题目没有整理,故在此开辟一块小空间. 我们再来看一道有关几何的问题.(Problem source:hdu2073)    数理分析:虽然这道题异常的简单,基本算不上计算几何这个专题当中的题目,但是把它拿到这里来,是源于这道简单几何题的思路其实体现了计算几何整个体系中比较重要的思维.

【习题整理】计算几何基础

bzoj1074[Scoi2007]折纸 思路:考虑倒着做,每次将在折叠的直线右边的扔掉,左边的点再对称一次加入: 算几知识:求向量关于法向量的对称向量 点$A$关于点$B$对称的点$C = 2B - A$ 如果要求$\vec{A}$关于法向量$\vec{l}$的对称向量$\vec{A'}$: 可以考虑都平移到原点 利用点积求出$\vec{A}$在$\vec{l}$上的投影点$D$, 再将点$A$关于$D$对称到$A'$: $A'$的坐标就是向量$\vec{A'}$ 1 #include<bit