UVALive 4728 (凸包 旋转卡壳)
2015-11-11 10:28
357 查看
板子题 每个正方形加进去4个点。
#include <cstring> #include <cmath> #include <iostream> #include <algorithm> #include <cstdio> using namespace std; typedef unsigned long long ll; #define maxn 411111 #define pi acos (-1) #define rotate Rotate const double eps = 1e-8; 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 n, m, tot; point p[maxn], ch[maxn]; int ConvexHull () { 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; } double dis (point a, point b) { double xx = a.x-b.x, yy = a.y-b.y; return xx*xx+yy*yy; } double rotate_calipers (point *p) { double ans = 0; int cur = 1; for (int i = 0; i < m; i++) { while (cross (p[(cur+1)%m]-p[cur], p[(i+1)%m]-p[i]) < 0) cur = (cur+1)%m; ans = max (ans, max (dis (p[i], p[cur]), dis (p[(i+1)%m], p[(cur+1)%m]))); } return ans; } int main () { //freopen ("in", "r", stdin); int t; cin >> t; while (t--) { cin >> n; tot = 0; for (int i = 0; i < n; i++) { double x, y, w; cin >> x >> y >> w; for (int p1 = 0; p1 <= 1; p1++) for (int p2 = 0; p2 <= 1; p2++) p[tot++] = point (x+p1*w, y+p2*w); } n = tot; m = ConvexHull (); printf ("%lld\n", (long long) rotate_calipers (ch)); } return 0; }
相关文章推荐
- Spring中如何配置Hibernate事务
- 3个著名加密算法(MD5、RSA、DES)的解析
- 求助帖 编译通过,链接不行
- 【编程开发】 C与C++中的关于函数指针的强制类型转换与指针函数的关系
- IOS_AudioToolbox音效
- Cordova添加KeyMob广告管理库中文教程
- 不知道错在了哪里,请求帮忙,谢谢
- pAdTy_-2 构建内容共享的应用程序
- 随机验证码的生成(手机或者邮箱验证码)
- android 捕获全局异常
- AngularJS中$on、$emit和$broadcast的使用
- Block基础知识
- matlab使用
- 【转】缓存淘汰算法系列之1——LRU类
- Gitbook安装
- Oracle11g ORA-12541
- 安卓数据库框架LitePal(五):存储操作
- 手把手教你使用Git
- push pop和模态视图
- onNewIntent