POJ2007 凸包

2024-05-04 19:58
文章标签 凸包 poj2007

本文主要是介绍POJ2007 凸包,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

题目:题目链接

这道题目就是模版题,套用凸包的计算模版就行了

#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;#define maxn 55
#define pi acos(-1)struct Point
{int x, y;
} point[maxn];bool operator <(const Point &a, const Point &b)
{return atan2(a.y, a.x) < atan2(b.y, b.x);
}double cal(double a)
{if (a < 0)return a + 2 * pi;return a;
}int main()
{scanf("%d%d", &point[0].x, &point[0].y);int n = 0;while (scanf("%d%d", &point[n].x, &point[n].y) != EOF)n++;sort(point, point + n);double temp = 0;point[n] = point[0];int s;for (int i = 0; i < n; i++){double a = cal(atan2(point[i + 1].y, point[i + 1].x) - atan2(point[i].y, point[i].x));if (a > temp){temp = a;s = (i + 1) % n;}}printf("(0,0)\n");for (int i = 0; i < n; i++)printf("(%d,%d)\n", point[(s + i) % n].x, point[(s + i) % n].y);return 0;
}


努力努力...

这篇关于POJ2007 凸包的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/959997

相关文章

AtCoder ABC 365G 凸包 + 二分

题意 AtCoder ABC 365G Freestyle 题解 考虑任两种操作 ( A i , B i ) (A_{i},B_{i}) (Ai​,Bi​)和 ( A j , B j ) (A_{j},B_{j}) (Aj​,Bj​),则他们的任意组合可以表示为 ( t A i + ( 1 − t ) A j , t B i + ( 1 − t ) B j ) \big(tA_{i}+(1-

poj2187凸包

今天复习了一下凸包,感觉对于它的理解又加深了,凸包注意的有几点:1基准点在最下面的最左边(习惯性的,注意不只是最下面)2,另外零要重新定义,不再只是一个数,而是一个范围,那么此时对于判零的一系列操作就要注意了,什么时候为右端点,什么时候为左端点,什么时候要进行判零操作等等,3叉乘,要注意与qsort的结合,不要搞混了。 下面是这题的代码: #include <iostream>#includ

判断凸包

下面以hdu2108为例,说明一下判断凸包的算法。 直接贴此题代码: 232K+15MS #include <stdio.h>#include <stdlib.h>#define Max 1010typedef struct Point{int x;int y;}point;point node[Max];int n;int det(int x1,int y1,int x2,

【NetTopologySuite类库】生成凸包

介绍 计算几何体的凸包。凸包是最小的凸几何体,包含输入几何体中的所有点。使用Graham Scan算法。 API地址: https://nettopologysuite.github.io/NetTopologySuite/api/NetTopologySuite.Algorithm.ConvexHull.html 示意图 示例代码 需在NuGet中安装NetTopologySuit

HDOJ 1348 基本二维凸包问题

这次写的凸包用的是Graham scan算法 就数据结构上只是简单地运用了一个栈 #include<stdio.h>#include<cmath>#include<algorithm>//#define LOCALusing namespace std;const int max1=1000;typedef struct point{int x;int y;}point;

uva 11072 - Points(凸包)

题目链接:uva 11072 - Points 求出凸包,判断点是否在凸包内即可。 #include <cstdio>#include <cstring>#include <cmath>#include <vector>#include <complex>#include <algorithm>using namespace std;typedef pair<int

uva 1303 - Wall(凸包)

题目链接:uva 1303 - Wall 求出凸包加个圆周。 #include <cstdio>#include <cstring>#include <cmath>#include <vector>#include <complex>#include <algorithm>using namespace std;typedef pair<int,int> pii;

hdu 5448 Marisa’s Cake(几何+凸包)

题目链接:hdu 5448 Marisa’s Cake 解题思路 这题和zoj 3871 Convex Hull有点像,不过点数比较大,不能接受 o(n2) o(n^2)的算法。但是题目给定的是一个凸包,所以可以通过化简,在 o(n) o(n)的复杂度内计算出答案。 首先,对于一个三角形ABC SABC=fA×fB+fB×fC+fC×fA(fi表示点i和原点组成的向量) S_{

暴力法解决最近对问题和凸包问题-实现可视化

目录 最近对问题 凸包问题 最近对问题 顾名思义就是采用蛮力法求出所有点之间的距离,然后进行比较找出第一个最近对,一个一个进行比较。 大概思路就是如图(每个圈代表一个数对) 第一个和其他四个比较 第二个和其他三个比较 ....... 最后比较最小的 代码 图形化界面主要是easyx的graphics #include<iostream>#include <

POJ 1113 凸包模版题

题目: 题目链接 题目的意思就是让你求出凸包,然后在一凸包向外延伸L米。问此时的环的长度是多少? #include <iostream>#include <cstdio>#include <string>#include <string.h>#include <map>#include <vector>#include <cstdlib>#include <cmath>#