LightOj1203 - Guarding Bananas(凸包求多边形中的最小角)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1203
题意:给你一个点集,求凸包中最小的角;模板题,但是刚开始的时候模板带错了,错的我都想吐了;
#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
#define met(a, b) memset(a, b, sizeof(a))
const double eps = 1e-;
const double PI = acos(-);
const int N = ; struct point
{
double x, y;
point(double x=, double y=) : x(x), y(y){}
friend point operator - (const point& p1, const point& p2)
{
return point(p1.x-p2.x, p1.y-p2.y);
}
friend double operator ^ (const point& p1, const point& p2)
{
return p1.x*p2.y - p1.y*p2.x;
}
}p[N], res[N];
double Dist(point p1, point p2)
{
double dx = p1.x - p2.x, dy = p1.y - p2.y;
return sqrt(dx*dx + dy*dy);
}
bool cmp1(point p1, point p2)
{
if(p1.y == p2.y)
return p1.x < p2.x;
return p1.y < p2.y;
}
bool cmp2(point p1, point p2)///极角排序;若极角相同,距离近的在前面;
{
double k = (p1-p[])^(p2-p[]);
if( k>eps || (fabs(k)<eps && Dist(p1, p[]) < Dist(p2, p[]) ))
return ;
return ;
}
int Graham(int n)
{
res[] = p[];if(n == ) return ;
res[] = p[];if(n == ) return ;
int top = ;
for(int i=; i<n; i++)
{
while(top && ((res[top]-res[top-])^(p[i]-res[top-])) <= ) top--;
res[++top] = p[i];
}
return top+;
}
int main()
{
int n, T, tCase = ;
scanf("%d", &T);
while(T--)
{
scanf("%d", &n);
for(int i=; i<n; i++)
scanf("%lf %lf", &p[i].x, &p[i].y);
sort(p, p+n, cmp1);///p[0]为最下方靠左的点;
sort(p+, p+n, cmp2);///以p[0]为基点,按叉积进行排序;
int cnt = Graham(n);///求凸包的顶点个数cnt,保存在res中,下标从0开始;
if(cnt < )
{
printf("Case %d: 0\n", tCase++);
continue;
}
double ans = ;
res[cnt] = res[], res[cnt+] = res[];
for(int i=; i<=cnt; i++)
{
double a = Dist(res[i-], res[i+]);
double b = Dist(res[i-], res[i]);
double c = Dist(res[i], res[i+]);
ans = min(ans, acos((b*b+c*c-a*a)/(*b*c)));
}
printf("Case %d: %.6f\n", tCase++, ans*/PI);
}
return ;
}
LightOj1203 - Guarding Bananas(凸包求多边形中的最小角)的更多相关文章
- poj 3348 Cows 凸包 求多边形面积 计算几何 难度:0 Source:CCC207
Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7038 Accepted: 3242 Description ...
- LightOJ 1203 Guarding Bananas (凸包最小顶角)
题目链接:LightOJ 1203 Problem Description Once there was a lazy monkey in a forest. But he loved banana ...
- POJ-3348 Cows 计算几何 求凸包 求多边形面积
题目链接:https://cn.vjudge.net/problem/POJ-3348 题意 啊模版题啊 求凸包的面积,除50即可 思路 求凸包的面积,除50即可 提交过程 AC 代码 #includ ...
- Guarding Bananas
Guarding Bananas Once there was a lazy monkey in a forest. But he loved banana too much. One day the ...
- opencv---(腐蚀、膨胀、边缘检测、轮廓检索、凸包、多边形拟合)
一.腐蚀(Erode) 取符合模板的点, 用区域最小值代替中心位置值(锚点) 作用: 平滑对象边缘.弱化对象之间的连接. opencv 中相关函数:(erode) // C++ /** shape: ...
- poj1584(判断凸包+求点到线段的距离)
题目链接:https://vjudge.net/problem/POJ-1584 题意:首先要判断凸包,然后判断圆是否在多边形中. 思路: 判断凸包利用叉积,判断圆在多边形首先要判断圆心是否在多边形中 ...
- UVALive 4426 Blast the Enemy! --求多边形重心
题意:求一个不规则简单多边形的重心. 解法:多边形的重心就是所有三角形的重心对面积的加权平均数. 关于求多边形重心的文章: 求多边形重心 用叉积搞一搞就行了. 代码: #include <ios ...
- POJ 3130 How I Mathematician Wonder What You Are!(半平面交求多边形的核)
题目链接 题意 : 给你一个多边形,问你该多边形中是否存在一个点使得该点与该多边形任意一点的连线都在多边形之内. 思路 : 与3335一样,不过要注意方向变化一下. #include <stdi ...
- POJ 1113 Wall 凸包求周长
Wall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 26286 Accepted: 8760 Description ...
随机推荐
- 什么是SQL注入式攻击
什么是SQL注入式攻击? 所谓SQL注入式攻击,就是攻击者把SQL命令插入到Web表单的输入域或页面请求的查询字符串,欺骗服务器执行恶意的SQL命令.在某些表单中,用户输入的内容直接用来构造(或者影响 ...
- FlyCapture2 VS2010 Configuration
Add in the system Path: C:\Program Files (x86)\Point Grey Research\FlyCapture2\bin Project->Proje ...
- java 从args[]中赋值和程序直接赋值不一样?
System.out.println("对应的中文: " + decodeUnicode(args[0])); 赋值args[0] = “\u7b80\u4ecb” System. ...
- Disaster recovery best practices for Symantec Endpoint Protection 12.1
https://support.symantec.com/en_US/article.TECH160736.html
- 硬盘参数之TLER
“你们根本不知道nas盘是用来干啥的,准确的说,要nas盘就是要tler技术,这样才适合用在nas上. TLER=Time-Limited Error Recovery 这么说吧,普通的硬盘(不带TL ...
- 禁用符合一定条件的AD对象 (含Filter参数的写法)
Get-ADComputer -Filter "(sAMAccountType -eq 805306369)" -SearchBase "OU=Computers,OU= ...
- 【液晶模块系列基础视频】3.3fatfs接口函数的使用3
============================= 技术论坛:http://www.eeschool.org 博客地址:http://xiaomagee.cnblogs.com 官方网店:ht ...
- Yii2.0 URL美化
1. 程序初始化注册文件,加入如下: 'urlManager' =>[ 'class' => 'yii\web\UrlManager', 'showScriptName' =>fal ...
- ASP.NET MVC4系列验证机制、伙伴类共享源数据信息(数据注解和验证)
一,mvc前后台验证 自定义属性标签MyRegularExpression using System; using System.Collections.Generic; using System.C ...
- windows下Gulp安装
目录: 1.安装nodejs2.使用命令行3.npm介绍4.选装cnpm5.全局安装gulp6.新建package.json文件7.本地安装gulp插件8.新建gulpfile.js文件9.运行gul ...