博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU1392 Surround the Trees
阅读量:4952 次
发布时间:2019-06-11

本文共 2851 字,大约阅读时间需要 9 分钟。

凸包

水一下。。构造凸包求周长。。

#include 
#define INF 0x3f3f3f3f#define full(a, b) memset(a, b, sizeof a)#define FAST_IO ios::sync_with_stdio(false)using namespace std;typedef long long LL;inline int lowbit(int x){ return x & (-x); }inline int read(){ int ret = 0, w = 0; char ch = 0; while(!isdigit(ch)){ w |= ch == '-', ch = getchar(); } while(isdigit(ch)){ ret = (ret << 3) + (ret << 1) + (ch ^ 48); ch = getchar(); } return w ? -ret : ret;}inline int lcm(int a, int b){ return a / __gcd(a, b) * b; }template
inline A fpow(A x, B p, C lyd){ A ans = 1; for(; p; p >>= 1, x = 1LL * x * x % lyd)if(p & 1)ans = 1LL * x * ans % lyd; return ans;}#define eps 1e-6;struct Point{ double x, y; Point(double x, double y): x(x), y(y){} Point operator + (Point &a){ return Point(x + a.x, y + a.y); } Point operator - (Point &a){ return Point(x - a.x, y - a.y); } bool operator < (const Point &a) const { if(x == a.x) return y < a.y; return x < a.x; } bool operator == (Point &a){ if(x == a.x && y == a.y) return true; return false; } double abs(){ return sqrt(x * x + y * y); }};typedef Point Vector;vector
p, u, l;int n;double cross(Vector a, Vector b){ return a.x * b.y - a.y * b.x;}bool isClock(Point a, Point b, Point c){ Vector x = b - a; Vector y = c - a; return cross(x, y) < eps;}double dis(Point a, Point b){ return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));;}int main(){ while(~scanf("%d", &n) && n){ p.clear(), u.clear(), l.clear(); for(int i = 1; i <= n; i ++){ double x, y; scanf("%lf%lf", &x, &y); p.push_back(Point(x, y)); } if(n == 1){ printf("0.00\n"); continue; } if(n == 2){ printf("%.2lf\n", dis(p[0], p[1])); continue; } sort(p.begin(), p.end()); u.push_back(p[0]), u.push_back(p[1]); for(int i = 2; i < p.size(); i ++){ for(int n = u.size(); n >= 2 && (!isClock(u[n - 2], u[n - 1], p[i])); n --) u.pop_back(); u.push_back(p[i]); } l.push_back(p[p.size() - 1]), l.push_back(p[p.size() - 2]); for(int i = p.size() - 3; i >= 0; i --){ for(int n = l.size(); n >= 2 && (!isClock(l[n - 2], l[n - 1], p[i])); n --) l.pop_back(); l.push_back(p[i]); } for(int i = 1; i < u.size() - 1; i ++){ l.push_back(u[i]); } double ans = 0; for(int i = 1; i < l.size(); i ++){ ans += dis(l[i], l[i - 1]); } ans += dis(l[0], l[l.size() - 1]); printf("%.2lf\n", ans); } return 0;}

转载于:https://www.cnblogs.com/onionQAQ/p/11242619.html

你可能感兴趣的文章
Android SDK环境变量配置
查看>>
VM10虚拟机安装图解
查看>>
9、总线
查看>>
Git 笔记 - section 1
查看>>
JZOJ 4.1 B组 俄罗斯方块
查看>>
HDU6409 没有兄弟的舞会
查看>>
2018 Multi-University Training Contest 10 - TeaTree
查看>>
HDU6205 card card card
查看>>
2018 Multi-University Training Contest 10 - Count
查看>>
HDU6198 number number number
查看>>
HDU6438 Buy and Resell
查看>>
HDU6446 Tree and Permutation
查看>>
HDU6201 transaction transaction transaction
查看>>
HDU6203 ping ping ping
查看>>
前端小笔记
查看>>
《人人都是产品经理》书籍目录
查看>>
Netsharp系列文章目录结构
查看>>
如何在git bash中运行mysql
查看>>
OO第三阶段总结
查看>>
构建之法阅读笔记02
查看>>