Squares
来源:互联网 发布:框架图制作软件 编辑:程序博客网 时间:2024/04/30 01:38
Squares
.
.
题意:给出n个正方形,问最远的两个点距离多少
.
.
解法:旋转卡壳,计算二维平面最远的两个点
.
.
#include <cstdio>#include <algorithm>using namespace std;struct Point { int x, y; Point(int _x = 0, int _y = 0) { x = _x; y = _y; } Point operator -(const Point &b) { return Point(x - b.x, y - b.y); } int operator ^(const Point &b) const { return x*b.y-y*b.x; } int operator *(const Point &b) const { return x * b.x + y * b.y; }};int dist2(Point a, Point b) { return (a-b) * (a-b);}const int MAXN = 400010;Point list[MAXN];int Stack[MAXN], top;bool _cmp(Point p1, Point p2){ int tmp = (p1-list[0]) ^ (p2-list[0]); if (tmp > 0) return true; else if (tmp == 0 && dist2(p1, list[0]) <= dist2(p2, list[0])) { return true; } return false;}void Graham(int n){ Point p0; int k = 0; p0 = list[0]; for (int i = 1; i < n; i++) if (p0.y > list[i].y || (p0.y == list[i].y && p0.x > list[i].x)) { p0 = list[i]; k = i; } Point tmp = list[0]; list[0] = list[k]; list[k] = tmp; sort(list+1, list+n, _cmp); if (n==1) { top = 1; Stack[0] = 0; return; } if (n == 2) { top = 2; Stack[0] = 0; Stack[1] = 1; return; } Stack[0] == 0; Stack[1] = 1; top = 2; for (int i = 2; i < n; i++) { while (top > 1 && ((list[Stack[top-1]] - list[Stack[top-2]]) ^ (list[i] - list[Stack[top-2]])) <= 0) top--; Stack[top++] = i; }}int rotating_calipers(Point p[], int n){ int ans = 0; Point v; int cur = 1; for (int i = 0; i < n; i++) { v = p[i] - p[(i + 1) % n]; while ((v^(p[(cur+1)%n]-p[cur])) < 0) cur = (cur + 1) % n; ans = max(ans,max(dist2(p[i], p[cur]), dist2(p[(i+1)%n], p[(cur+1) % n]))); } return ans;}Point p[MAXN];int main(){ int t, n, rr; scanf("%d", &t); while (t--) { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d %d %d", &list[i * 4].x, &list[i * 4].y, &rr); list[(i*4+1)].x = list[i*4].x + rr; list[(i*4+1)].y = list[i*4].y + rr; list[(i*4+2)].x = list[i*4].x; list[(i*4+2)].y = list[i*4].y + rr; list[(i*4+3)].x = list[i*4].x + rr; list[(i*4+3)].y = list[i*4].y; } Graham(n*4); for (int i = 0; i < top; i++) { p[i] = list[Stack[i]]; } printf("%d\n", rotating_calipers(p, top)); }}
0 0
- Squares
- Squares
- Squares
- Squares
- Squares
- Squares
- Squares
- Squares
- Squares
- Least Squares
- Palindromic Squares
- hdu1264Counting Squares
- POJ2002 Squares
- 【STL】Squares
- palindromic squares
- Palindromic Squares
- Palindromic Squares
- Palindromic Squares
- PHP中 获取文件扩展名的N种方法
- TCP编程与UDP编程的步骤:
- Yii2创建程序更新和写入的日志捕捉
- HDU4793 2013 长沙 C (计算几何—点和圆的位置关系—解法①列方程求解[时间作自变量] —解法②向量积和sin角度求解长度再除以有方向的速度)
- 平衡二叉树
- Squares
- shareSDK分享_登陆
- 案例:e袋洗如何以用户为导向的高性价比闭环
- jsp页面跳转
- ASP.net mvc学习笔记
- maven配置默认的中央仓库,setting.xml配置
- 树-堆结构练习——合并果子之哈夫曼树
- androuid 安卓 popupwindow使用(新手必备)
- svn 版本回滚