EOJ 1189 wall 计算几何
来源:互联网 发布:项尖数据恢复注册码 编辑:程序博客网 时间:2024/06/05 14:16
思路就是先求凸包,然后可以证明出距离为L的城墙周长正好是凸包周长加上2*pi*L(画图可以看出)
#include "set"#include "map"#include "queue"#include "stack"#include "cmath"#include "cstdio"#include "cstdlib"#include "iostream"#include "algorithm"#define EPS 1e-10#define MAX_N 100000#define Pi acos(-1.0)#define INF 0x3f3f3f3f#pragma warning(disable:4996)#define up(i, low, high) for (int i = low; i < high; i++)#define down(i, high, low) for (int i = high; i >= low; i--)using namespace std;double add (double a, double b){if (abs (a + b) < EPS * (abs (a) + abs (b))) return 0;return a + b;}//二维向量结构体struct P{double x, y;P () {}P (double x, double y) : x (x), y (y) {};P operator + (P p){return P (add (x, p.x), add (y, p.y));}P operator - (P p){return P (add (x, -p.x), add (y, -p.y));}P operator * (double d){return P (x * d, y * d);}//内积double dot (P p){return add (x * p.x, y * p.y);}//外积double det (P p){return add (x * p.y, -y * p.x);}};P a[MAX_N];bool cmp_x (P a, P b){return a.x < b.x || (a.x == b.x && a.y < b.y);}//计算凸包vector<P> Graham (P* ps, int n){sort (ps, ps + n, cmp_x);//凸包的顶点数int k = 0;//构造中的凸包vector<P> qs (n * 2);//构造凸包的下侧up (i, 0, n){//注意要小于等于0while (k > 1 && (qs[k - 1] - qs[k - 2]).det (ps[i] - qs[k - 1]) <= 0) k--;qs[k++] = ps[i];}//构造凸包的上侧int t = k;down (i, n - 2, 0){while (k > t && (qs[k - 1] - qs[k - 2]).det (ps[i] - qs[k - 1]) <= 0) k--;qs[k++] = ps[i];}//0被扫描了两次qs.resize (k - 1);return qs;}//距离的平方double dis (P p, P q){return (p - q).dot (p - q);}int main (){//freopen ("D:\\Test_in.txt", "r", stdin);//freopen ("D:\\Test_out.txt", "w", stdout);int n, L;while (~scanf ("%d%d", &n, &L)){vector<int> p;up (i, 0, n) scanf ("%lf%lf", &a[i].x, &a[i].y);vector<P> Convex_Hull = Graham (a, n);double ans = 0;up (i, 0, Convex_Hull.size () - 1){ans += sqrt (dis (Convex_Hull[i], Convex_Hull[i + 1]));}//printf ("%.0f\n", ceil (ans));ans += sqrt (dis (Convex_Hull[Convex_Hull.size () - 1], Convex_Hull[0]));ans += 2 * Pi * L;printf ("%.0f\n", ans);}}
0 0
- EOJ 1189 wall 计算几何
- 【计算几何】Wall
- 【计算几何】poj1113 Wall
- [POJ1113] Wall && 计算几何
- 【POJ1113】【计算几何】Wall 题解
- [计算几何-凸包]pku1113-Wall
- POJ 1113 WALL(凸包-计算几何)
- 【计算几何】【求凸包】【POJ 1113】wall
- poj 1113 Wall (计算几何)
- poj1113——Wall(计算几何凸包)
- POJ 1113 Wall (计算几何-凸包)
- ACM-计算几何之Wall——poj1113
- hdu 1348 wall (计算几何,凸包)
- POJ1113(Wall) && Hdu1392(Surround the Trees) (计算几何--凸包)
- 计算几何 ( 凸包 )——Wall ( HDU 1248 )
- poj 1113 Wall 计算几何 凸包 Graham扫描
- POJ1113---Wall(基础计算几何:凸包入门)
- EOJ 1161 数学几何
- 常用基础 的代码,虽不常用,但是要会
- CentOS7安装和配置FTP
- CoreData数据验证失败仍然插入context的解决(一)
- Java中动态代理的实现
- 顺序容器vector、deque和List练习
- EOJ 1189 wall 计算几何
- 重温Spring之旅4——Classpath自动扫描把组件纳入spring容器中管理
- Easyx 学习总结
- Servlet.service() for servlet springmvc threw exception org.apache.jasper.JasperException: /WEB-INF/
- Linux下调试器GDB、makefile的使用
- Valid Palindrome
- motan学习笔记 四 motan Demo 之yar 分析
- 欢迎使用CSDN-markdown编辑器
- linux基础学习(1)