hdu2202 最大三角形(旋转卡壳)
来源:互联网 发布:知我药妆网假货多吗 编辑:程序博客网 时间:2024/06/05 19:20
hdu2202
题目
中文题
思路
学习了什么是旋转卡壳,求三角形面积的话就是多加了一个底边是哪两个点组成的。
代码
#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=50010;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];bool OnSegment (point p, point a1, point a2){ return dcmp (cross (a1-p, a2-p)) == 0 && dcmp (dot (a1-p, a2-p)) < 0;}double rotate_calipers (int m){ if (m == 1 || m == 2) return 0; double ans = 0; int cur = 1; for (int add = 1; add < m; add++) { for (int i = 0; i < m; i++) { while (cross (ch[i]-ch[(i+add)%m], ch[(cur+1)%m]-ch[cur]) < 0) cur = (cur+1)%m; double res = max (cross (ch[(i+add)%m]-ch[i], ch[cur]-ch[i]), cross (ch[(i+add)%m]-ch[i], ch[(cur+1)%m]-ch[i])); ans = max (ans, res); } } return ans/2.0;}int main(){ while(scanf("%d",&n)!=EOF) { for(int i=0; i<n; i++) scanf("%lf %lf",&p[i].x,&p[i].y); cnt=ConvexHull(p,ch,n); printf("%.2lf\n",rotate_calipers(cnt)); } return 0;}
0 0
- hdu2202 最大三角形(旋转卡壳)
- hdu 2202 最大三角形 (旋转卡壳)
- hdu2202 凸包+旋转卡壳
- HDU2202最大三角形
- poj2079 Triangle (旋转卡壳之最大三角形)
- HDU 2202 最大三角形 (凸包+旋转卡壳)
- POJ2079 旋转卡壳 凸包内最大三角形
- 旋转卡壳法求最大三角形
- 【凸包】HDU2202最大三角形
- hdu2202 最大三角形 凸包
- 计算几何——最大三角形【HDU2202】
- POJ 2079 求最大三角形面积 (凸包+旋转卡壳)
- POJ 2079 Triangle(凸包_旋转卡壳之最大三角形面积)
- POJ 2079 Triangle(凸包+旋转卡壳求最大三角形面积)
- ZOJ 2419-- Triangle-凸包+旋转卡壳求最大面积三角形(计算几何)
- POJ 2079 Triangle(旋转卡壳计算平面点集最大三角形面积)
- POJ 2079 Triangle(凸包+旋转卡壳,求最大三角形面积)
- POJ 2079 Triangle (凸包中的最大三角形&旋转卡壳)
- swift中UIAlertView的使用
- Operating Systems
- JS屏蔽Backspace跳转网页
- linux之let用法
- 设计模式--策略模式
- hdu2202 最大三角形(旋转卡壳)
- Spring boot VO字段设置后台传入前台日期格式
- 在html页面显示pdf,实现pdf的预览和下载
- 二叉树的非递归的实现
- Python三级菜单大概思路
- easy ui 回车换输入焦点
- django如何解决Ajax跨域访问问题?
- iOS中arc的设置与使用-fobjc-arc或者-fno-objc-arc
- MobiCom 2016 conference - SEEM