nyoj 226 && hdu HDU 1348 && poj 1113 wall [凸包周长]
2014-07-21 18:20
435 查看
题目链接:nyoj poj hdu
题目的意思很是简单,就是求一个凸包的周长+以L为半径的圆的周长。
凸包算法有待完善。。。。。
Code:
慢慢学计算几何!!。
题目的意思很是简单,就是求一个凸包的周长+以L为半径的圆的周长。
凸包算法有待完善。。。。。
Code:
#include <cstdio> #include <cstring> #include <algorithm> #include <cmath> using namespace std; const int N = 1e3 + 4; const double PI = acos(-1); const double eps = 1e-8; struct Point{ double x, y; }p ; double cross(Point o, Point a, Point b){ return (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x); } double Distance(Point a, Point b){ return sqrt(pow(a.x - b.x, 2.0) + pow(a.y - b.y, 2.0)); } bool cmp(Point a, Point b){ if(a.y < b.y || (a.y == b.y && a.x < b.x)) return true; return false; } bool cmp1(Point a, Point b){ if(cross(p[0], a, b) > eps ) return true; else if(fabs(cross(p[0], a, b)) < eps && Distance(a, p[0]) > Distance(b, p[0])) return true; else return false; } double Judge(Point a, Point b, Point c){ if(cross(a, b, c) > eps) return true; else if(fabs(cross(a, b, c)) < eps && Distance(b, a) < Distance(b, c)) return true; else return false; } void Graham_scan(int n, double r){ sort(p, p + n, cmp); sort(p + 1, p + n, cmp1); Point st ; int top = 0; st[top ++] = p[0]; st[top ++] = p[1]; for(int i = 2; i < n; i ++){ while(top >= 2 && Judge(st[top - 1], st[top - 2], p[i])){ top --; } st[top ++] = p[i]; } st[top] = st[0]; double ans = 0; for(int i = 0; i < top; i ++){ ans += Distance(st[i], st[i + 1]); } ans += (PI * r * 2.0); printf("%.0f\n",ans); } int main(){ int n; double r; bool flag = false; while(~scanf("%d %lf",&n, &r)){ for(int i = 0; i < n; i ++){ scanf("%lf %lf",&p[i].x, &p[i].y); } if(flag) puts(""); Graham_scan(n,r); flag = true; } return 0; }
慢慢学计算几何!!。
相关文章推荐
- POJ 1113 && HDU 1348 Wall (凸包周长 graham扫描法)
- POJ 1113 && HDU 1348 Wall(凸包)
- HDU 1348 && POJ 1113 Wall(凸包)
- POJ 1113 Wall(计算几何--凸包的周长)
- POJ 1113 Wall(凸包周长)
- POJ 1113 Wall 凸包求周长
- 【解题报告】 POJ 1113 Wall -- 求凸包周长
- POJ1113(Wall) && Hdu1392(Surround the Trees) (计算几何--凸包)
- POJ1113 Wall(凸包周长)
- POJ 1113 || HDU 1348: wall(凸包问题)
- POJ 1113 || HDU 1348: wall(凸包问题)
- POJ 1113 Wall(求凸包周长)
- POJ 1113 Wall 凸包求周长
- POJ 1113 Wall(凸包周长)
- POJ 1113 Wall(Graham求凸包周长)
- POJ 1113 Wall【凸包周长】
- POJ 1113 Wall (凸包+求周长)
- poj 1113:Wall(计算几何,求凸包周长)
- POJ 1113 Wall(凸包 多边形周长)
- POJ 1113 Wall (凸包周长)