Lightoj1203 Guarding Bananas(凸包)
来源:互联网 发布:软件开发好学吗? 编辑:程序博客网 时间:2024/05/20 00:15
Lightoj1203
题目
有一片香蕉园,一只猴子想知道能看到所有香蕉的最小角度。
思路
求凸包,枚举角度。
代码
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>#define pi acos (-1)#define rotate Rotateusing namespace std;typedef long long ll;const double eps = 1e-8;const int maxn=100010;const double INF = 1e20;int dcmp (double x){ if (fabs (x) < eps) return 0; else return x < 0 ? -1 : 1;}struct point{ double x, y; point (double _x = 0, double _y = 0) : x(_x), y(_y) {} point operator - (point a) const { return point (x-a.x, y-a.y); } point operator + (point a) const { return point (x+a.x, y+a.y); } bool operator < (const point &a) const { return x < a.x || (x == a.x && y < a.y); } bool operator == (const point &a) const { return dcmp (x-a.x) == 0 && dcmp (y-a.y) == 0; }};point operator * (point a, double p){ return point (a.x*p, a.y*p);}double cross (point a, point b){ return a.x*b.y-a.y*b.x;}double dot (point a, point b){ return a.x*b.x + a.y*b.y;}int ConvexHull (point *p, point *ch, int n){ sort (p, p+n); int m = 0; for (int i = 0; i < n; i++) { while (m > 1 && cross (ch[m-1]-ch[m-2], p[i]-ch[m-1]) <= 0) m--; ch[m++] = p[i]; } int k = m; for (int i = n-2; i >= 0; i--) { while (m > k && cross (ch[m-1]-ch[m-2], p[i]-ch[m-1]) <= 0) m--; ch[m++] = p[i]; } if (n > 1) m--; return m;}int cnt,n;point p[maxn],ch[maxn];double rad (point a, point b) //两个向量的夹角{ return fabs (atan2 (fabs (cross (a, b)), dot (a, b)) );}double rad_degree (double rad) //弧度转化为角度{ return rad/pi*180;}int main(){ int T; scanf("%d",&T); int kase=1; while(T--) { printf ("Case %d: ", kase++); scanf("%d",&n); for(int i=0; i<n; i++) scanf("%lf %lf",&p[i].x,&p[i].y); double ans=INF; cnt=ConvexHull(p,ch,n); for(int i=0;i<cnt;i++) { ans=min(ans,rad(ch[(i+1)%cnt]-ch[i],ch[(i-1+cnt)%cnt]-ch[i])); } printf ("%.10f\n", rad_degree(ans)); } return 0;}
0 0
- Lightoj1203 Guarding Bananas(凸包)
- light1203 - Guarding Bananas【凸包】
- 【凸包构造】LightOJ 1203 Guarding Bananas
- LightOJ 1203 Guarding Bananas (凸包最小顶角)
- LightOJ 1203 Guarding Bananas(凸包、直线夹角)
- LightOJ 1203 Guarding Bananas
- LightOJ 1203 - Guarding Bananas
- LightOJ1203->求凸包最小内角角度
- 情绪失控 go bananas
- Sicily 1945. Monkeys & Bananas
- A. Soldier and Bananas
- Codeforces546A:Soldier and Bananas
- 【CodeChef】LCH15JGH Many bananas
- Coderforces Soldier and Bananas
- Guarding the Farm
- UVa11214 - Guarding the Chessboard
- 11214 - Guarding the Chessboard
- Guarding the Chessboard UVA
- 大数取余
- C# 如何获取错误所在行数
- 均值滤波的快速解法
- 用VS2015编译MPC-HC
- Android学习笔记44:JSON数据解析
- Lightoj1203 Guarding Bananas(凸包)
- cube-sdk
- eclipse Android开发百度地图只显示网格问题
- Flume学习笔记之初识(一)
- Android学习笔记45:JSON数据解析(GSON方式)
- 生产环境CPU过高问题
- Jenkins设置邮箱
- socket connect函数理解
- 乐观锁和悲观锁分别是什么 区别在哪里?