Beauty Contest

直接跑一个凸包,然后跑一跑旋转卡壳,求最大值就行了。

/*Author : lifehappy
*/
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <iostream>using namespace std;const double pi = acos(-1.0);
const double eps = 1e-5;
const double inf = 1e100;int Sgn(double x) {return x < -eps ? -1 : x > eps;
}struct Vector {double x, y;bool operator < (Vector &a) const {return x < a.x;}void print() {printf("%f %f\n", x, y);}void read() {scanf("%lf %lf", &x, &y);}Vector(double _x = 0, double _y = 0) : x(_x), y(_y) {}double mod() {return sqrt(x * x + y * y);}double mod2() {return x * x + y * y;}Vector operator + (const Vector &a) {return Vector(x + a.x, y + a.y);}Vector operator - (const Vector &a) {return Vector(x - a.x, y - a.y);}double operator * (const Vector &a) {return x * a.x + y * a.y;}double operator ^ (const Vector &a) {return x * a.y - y * a.x;}Vector Rotate(double angle) {return Vector(x * cos(angle) - y * sin(angle), x * sin(angle) + y * cos(angle));}Vector operator << (const double &a) {return Vector(x * a, y * a);}Vector operator >> (const double &a) {return Vector(x / a, y / a);}bool operator == (const Vector & a) {return (Sgn(x - a.x) == 0) && (Sgn(y - a.y) == 0);}
};typedef Vector Point;double Dis_pp(Point a, Point b) {return sqrt((a - b) * (a - b));
}double Angle(Vector a, Vector b) {//[0, 2pi)double ans = atan2(a ^ b, a * b);return ans < 0 ? ans + 2 * pi : ans;// return atane(a ^ b, a * b);
}double To_lefttest(Point a, Point b, Point c) {return (b - a) ^(c - a);
}int Toleft_test(Point a, Point b, Point c) {return Sgn((b - a) ^ (c - a));
}struct Line {Point st, ed;Line(Point _st = Point(0, 0), Point _ed = Point(0, 0)) : st(_st), ed(_ed) {}bool operator < (const Line &t) {return st.x < t.st.x;}void read() {scanf("%lf %lf %lf %lf", &st.x, &st.y, &ed.x, &ed.y);}
};bool Parallel(Line a, Line b) {return Sgn((a.st - a.ed) ^ (b.st - b.ed)) == 0;
}bool Is_cross(Line a, Line b) {return Toleft_test(a.st, a.ed, b.st) * Toleft_test(a.st, a.ed, b.ed) <= 0 && Toleft_test(b.st, b.ed, a.st) * Toleft_test(b.st, b.ed, a.ed) <= 0;
}Point Cross_point(Line a, Line b) {if(!Is_cross(a, b)) {return Point(inf, inf);}else {double a1 = fabs(To_lefttest(a.st, a.ed, b.st)), a2 = fabs(To_lefttest(a.st, a.ed, b.ed));return ((b.st << a2) + (b.ed << a1)) >> (a1 + a2);}
}Point Intersect_point(Line a, Line b) {double a1 = a.st.y - a.ed.y, b1 = a.ed.x - a.st.x, c1 = a.st.x * a.ed.y - a.ed.x * a.st.y;double a2 = b.st.y - b.ed.y, b2 = b.ed.x - b.st.x, c2 = b.st.x * b.ed.y - b.ed.x * b.st.y;return Point((c1 * b2 - c2 * b1) / (a2 * b1 - a1 * b2), (a2 * c1 - a1 * c2) / (a1 * b2 - a2 * b1));
}Point Shadow(Line a, Point b) {Point dir = a.ed - a.st;return a.st + (dir << (((b - a.st) * dir) / dir.mod2()));
}Point Reflect(Line a, Point b) {return (Shadow(a, b) << 2) - b;
}bool inmid(double a, double b, double x) {if(a > b) swap(a, b);return Sgn(x - a) >= 0 && Sgn(b - x) >= 0;
}bool Point_in_line(Line a, Point b) {if(Toleft_test(a.st, a.ed, b) != 0) return false;return inmid(a.st.x, a.ed.x, b.x) && inmid(a.st.y, a.ed.y, b.y);
}double Dis_lp(Line a, Point b) {Point h = Shadow(a, b);if(Point_in_line(a, h)) {return Dis_pp(h, b);}return min(Dis_pp(a.st, b), Dis_pp(a.ed, b));
}// double Dis_ll(Line a, Line b) {//     if(Is_cross(a, b)) return 0;
//     return min({Dis_lp(a, b.st), Dis_lp(a, b.ed), Dis_lp(b, a.st), Dis_lp(b, a.ed)});
// }double Area(vector<Point> p, int n) {double ans = 0;for(int i = 0; i < n; i++) {ans += p[i] ^ p[(i + 1) % n];}return 0.5 * ans;
}double len(vector<Point> p, int n) {double ans = 0;for(int i = 0; i < n; i++) {ans += Dis_pp(p[i], p[(i + 1) % n]);}return ans;
}bool Is_convex(Point *a, int n) {bool flag[3] = {0, 0, 0};for(int i = 0; i < n; i++) {flag[Sgn(To_lefttest(a[i], a[(i + 1) % n], a[(i + 2) % n])) + 1] = true;if(flag[0] && flag[2]) return false;}return true;
}Point p0;bool cmp_graham(Point a, Point b) {int flag = Toleft_test(p0, a, b);return flag == 0 ? Dis_pp(p0, a) < Dis_pp(p0, b) : flag > 0;
}vector<Point> Graham(vector<Point> &a, int n) {p0 = a[0];for(int i = 0; i < n; i++) {if(a[i].y < p0.y || (a[i].y == p0.y && a[i].x < p0.x)) {p0 = a[i];}}vector<Point> ans;sort(a.begin(), a.end(), cmp_graham);if(n == 1) {ans.push_back(a[0]);return ans;}if(n == 2) {ans.push_back(a[0]);ans.push_back(a[1]);return ans;}ans.push_back(a[0]);ans.push_back(a[1]);int sz = 2;for(int i = 2; i < n; i++) {while(sz > 1 && To_lefttest(ans[sz - 2], ans[sz - 1], a[i]) <= 0) {ans.pop_back();sz--;}ans.push_back(a[i]);sz++;}return ans;
}bool cmp_andrew(Point a, Point b) {if(Sgn(a.x - b.x) == 0)    return a.y < b.y;return a.x < b.x;
}vector<Point> Andrew(vector<Point> &a, int n) {sort(a.begin(), a.end(), cmp_andrew);int p1 = 0, p2;vector<Point> ans;for(int i = 0; i < n; i++) {while(p1 > 1 && Toleft_test(ans[p1 - 2], ans[p1 - 1], a[i]) <= 0)   ans.pop_back(), p1--;ans.push_back(a[i]), p1++;}p2 = p1;for(int i = n - 2; i>= 0; i--) {while(p2 > p1 && Toleft_test(ans[p2 - 2], ans[p2 - 1], a[i]) <= 0)  ans.pop_back(), p2--;ans.push_back(a[i]), p2++;}ans.pop_back();return ans;
}double Get_angle(Line a) {return atan2(a.ed.y - a.st.y, a.ed.x - a.st.x);
}bool cmp_Half_lane_intersection(Line a, Line b) {Vector va = a.ed - a.st, vb = b.ed - b.st;double A =  Get_angle(va), B = Get_angle(vb);if (Sgn(A - B) == 0) return Sgn(((va) ^ (b.ed - a.st))) != -1;return Sgn(A - B) == -1;
}bool On_right(Line a, Line b, Line c) {Point o = Intersect_point(b, c);if (Sgn((a.ed - a.st) ^ (o - a.st)) < 0) return true;return false;
}const int N = 2e3 + 10;Line que[N];double Half_lane_intersection(vector<Line> &a) {sort(a.begin(), a.end(), cmp_Half_lane_intersection);int head = 0, tail = 0, cnt = 0, n = a.size();for(int i = 0; i < n - 1; i++) {if(Sgn(Get_angle(a[i]) - Get_angle(a[i + 1])) == 0) continue;a[cnt++] = a[i];}a[cnt++] = a[n - 1];for(int i = 0; i < cnt; i++) {while(tail - head > 1 && On_right(a[i], que[tail - 1], que[tail - 2])) tail--;while(tail - head > 1 && On_right(a[i], que[head], que[head + 1])) head++;que[tail++] = a[i];}while(tail - head > 1 && On_right(que[head], que[tail - 1], que[tail - 2])) tail--;while(tail - head > 1 && On_right(que[tail - 1], que[head], que[head + 1])) head++;n = tail - head;if(n < 3) return  0;vector<Point> ans;for(int i = head; i < tail; i++) {ans.push_back(Intersect_point(que[i], que[(i - head + 1) % n + head]));}return fabs(Area(ans, ans.size()));
}double RotateCalipers(vector<Point> a, int n) {double ans = 0; int now = 1;a.push_back(a[0]);for(int i = 0; i < n; i++){while(((a[now] - a[i + 1]) ^ (a[i] - a[i + 1])) < ((a[now + 1] - a[i + 1]) ^ (a[i] - a[i + 1]))) now = (now + 1) % n;ans = max(ans, max((a[now] - a[i]) * (a[now] - a[i]), (a[now] - a[i + 1]) * (a[now] - a[i + 1])));}return ans;
}int main() {// freopen("in.txt", "r", stdin);// freopen("out.txt", "w", stdout);// ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);int n;vector<Point> a;scanf("%d", &n);for(int i = 1; i <= n; i++) {Point temp;temp.read();a.push_back(temp);}a = Andrew(a, a.size());printf("%lld\n", (long long)(RotateCalipers(a, a.size()))    );return 0;
}

Beauty Contest(凸包 + 旋转卡壳(模板))相关推荐

  1. POJ - 2187 Beauty Contest (求距离最远点对-凸包+旋转卡壳/枚举 (旋转卡壳学习))

    链接:https://vjudge.net/problem/POJ-2187 题意:求求距离最远点对. 思路:肯定为凸包上的点,可枚举,也可根据凸包性质旋转卡壳求对踵点. 参考博客: https:// ...

  2. POJ 2187 凸包+旋转卡壳

    思路: 求个凸包 旋转卡壳一下 就求出来最远点对了 注意共线情况 也就是说   凸包如果有一堆点共线保留端点即可 //By SiriusRen #include <cmath> #incl ...

  3. hdu2202 凸包+旋转卡壳

    点击打开hdu2202 思路:最大三角形面积,那么肯定这三个点在最外围,所以先求凸包,然后用旋转卡壳求出那三个点求出面积最大. #include <iostream> #include & ...

  4. poj 2187 Beauty Contest (凸包: 最远点对,最长直径 , 旋转卡壳法)

    http://poj.org/problem?id=2187 题意: 最长的点对近距离的平方: 题解: 旋转卡壳法, 要注意的地方是,有 所有点共线的情况,所以,(求凸包时)要将,共线点去出 :    ...

  5. Gym - 102460L Largest Quadrilateral(几何-凸包+旋转卡壳求最大的四边形面积)

    题目链接:点击查看 题目大意:在笛卡尔坐标系上给出 n 个点,要求选出四个点,使得组成的四边形面积最大,求出这个最大的面积,注意此处组成的四边形不是严格意义上的四边形,只需要选四个点就行 题目分析:首 ...

  6. 旋转卡壳——模板(对踵点)

    这东西学了我大概两天吧..其实不应该学这么久的,但是这两天有点小困,然后学习时间被削了很多\(QwQ\) 说几个坑点. - 对于题目不保证有凸包的情况,要选用左下角的点,而非单纯的最下边的点构造凸包. ...

  7. 【BZOJ1185】【HNOI2007】最小矩形覆盖(凸包+旋转卡壳)

    传送门 题意:求最小矩阵覆盖 有这样一个结论:矩阵一定有一条边在凸包上(不会证) 那可以枚举每条边 同时旋转卡壳 只是这时不只维护一个对踵点对,同时在左右侧再维护一个最远点 可以发现左右最远点一定是和 ...

  8. poj 2187 Beauty Contest(凸包求解多节点的之间的最大距离)

    1 /* poj 2187 Beauty Contest 2 凸包:寻找每两点之间距离的最大值 3 这个最大值一定是在凸包的边缘上的! 4 5 求凸包的算法: Andrew算法! 6 */ 7 #in ...

  9. 凸包旋转卡壳(andrew)

    题目链接 如图计算上凸包时判断C1,C2,C3C_1,C_2,C_3C1​,C2​,C3​显然C3C_3C3​是经过A,BA,BA,B的上凸包 可以发现只需要通过A,BA,BA,B即可判断,通过观察可 ...

最新文章

  1. VTK:绘制轴AXES用法实战
  2. MariaDB配置、集群
  3. 前端学习(525):等分布局
  4. IDEA实时编译配置流程
  5. How to include library manually into maven local repository?
  6. 为什么 PUSH 推送要经常背锅?
  7. php公司共享 管理,php – 管理几个共享重叠函数和类的代码库
  8. 升级的Electric Cloud平台增添了大型机和微服务功能
  9. c语言file_C语言程序的编译和调试
  10. [转]使用SCOM 2012监控网络
  11. 【Java与智能设备】ch0501 Intent的使用
  12. 谷歌浏览器如何安装插件-以octotree为例
  13. Datax-HdfsWriter如何实现支持decimal类型数据写入
  14. 一根网线连接两台电脑,从而实现数据的传输
  15. 动态切换 web 报表中的统计图类型
  16. php html ubb,php UBB 解析实现代码
  17. BLE 技术(四)--- 链路层五种通信模式和空口协议设计 (Core_v5.2)
  18. 各种主流浏览器的调试
  19. 5G通信光模块是什么?5G通信光模块的发展方向如何?
  20. SCI、EI、ISTP国际三大检索分别指的是什么?

热门文章

  1. 服务器安全维护包含,服务器安全维护包含
  2. java简易日历程序报告_简单的日历小程序(java编写)
  3. java程序员遇到的问题_JAVA程序员最常遇见的10个异常
  4. 中国最美街景,带你一次看个够
  5. 乔布斯死后的300亿遗产终于被败光了,没想到竟是干了这件事
  6. 日本码农为了萝莉,竟然在GitHub上做这种事,“警察,快来抓我啊!”
  7. Nature封面:大团队日趋中庸,小团队更容易出颠覆性创新
  8. 预售┃一张纸一幅图,竟然提高了10倍的学习和工作效率!?
  9. 这个爱喝酒的酒鬼可真是让人操碎了心
  10. oracle asm磁盘头 备份,ASM磁盘头的第三个备份-Physically Addressed Metadata Redundancy