HDU 1348 (凸包)
2015-11-10 17:48
232 查看
题意是求凸包的周长加上一个半径为l的圆周长。
板子题。
板子题。
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ll; #define maxn 1111 #define pi acos (-1) struct point { double x, y; point (double _x = 0, double _y = 0) : x(_x), y(_y) {} point operator - (point a) const { return point (x-a.x, y-a.y); } bool operator < (const point &a) const { return x < a.x || (x == a.x && y < a.y); } }p[maxn]; const double eps = 1e-10; int dcmp (double x) { if (fabs (x) < eps) return 0; else return x < 0 ? -1 : 1; } double cross (point a, point b) { return a.x*b.y-a.y*b.x; } double dot (point a, point b) { return a.x*b.x + a.y*b.y; } int n, m; double l; point ch[maxn]; int ConvexHull () { sort (p, p+n); int m = 0; for (int i = 0; i < n; i++) { while (m > 1 && cross (ch[m-1]-ch[m-2], p[i]-ch[m-1]) <= 0) m--; ch[m++] = p[i]; } int k = m; for (int i = n-2; i >= 0; i--) { while (m > k && cross (ch[m-1]-ch[m-2], p[i]-ch[m-1]) <= 0) m--; ch[m++] = p[i]; } if (n > 1) m--; return m; } double dis (point a, point b) { double xx = a.x-b.x, yy = a.y-b.y; return sqrt (xx*xx + yy*yy); } int main () { //freopen ("in", "r", stdin); int t, kase = 0; scanf ("%d", &t); while (t--) { if (kase++) printf ("\n"); scanf ("%d%lf", &n, &l); for (int i = 0; i < n; i++) { scanf ("%lf%lf", &p[i].x, &p[i].y); } m = ConvexHull (); double ans = 0; for (int i = 0; i < m; i++) { ans += dis (ch[i], ch[(i+1)%m]); } ans += 2*pi*l; printf ("%lld\n", (long long) (ans+0.5)); } return 0; }
相关文章推荐
- keychain中我的证书与证书, p12与pem, apns, 推送
- 安装Qt /嵌入式
- CentOS安装apache
- 01 (maven+SSH)之项目简介
- hadoop-lzo-master 编译过程中遇到的问题
- leetcode 303: Range Sum Query - Immutable
- Database Net Services
- 聚类算法
- Wing IDE 5 的破解
- CentOS下安装Mysql数据库
- 安装Qt/X11
- C++基础::类设计的几大原则
- 用户热搜词相似度计算
- PhotoView 单击退出
- node-创建模块
- Oracle自增列创建方法
- LocalBroadcastManager—创建更高效、更安全的广播
- 通过Spring配置文件中bean中的property赋值
- 02 (maven+SSH)之需求分析
- python基础-内置数据类型