计算几何-凸包模板题目,Graham算法解。

 /* 1348 */
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std; #define MAXN 1005 typedef struct Point_t {
double x, y;
Point_t() {}
Point_t(double xx, double yy) {
x = xx; y = yy;
}
} Point_t; Point_t stack[MAXN];
Point_t points[MAXN];
const double PI = acos(-1.0);
int n; double Length(Point_t a, Point_t b) {
return sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));
} double cross(Point_t p0, Point_t p1, Point_t p2) {
return (p1.x - p0.x) * (p2.y - p0.y) - (p2.x - p0.x) * (p1.y - p0.y);
} bool comp(Point_t a, Point_t b) {
double k = cross(points[], a, b);
return !(k< || (k== && Length(points[], a)>Length(points[], b)));
} double Graham() {
double ret = ;
int i, j, k;
int top;
Point_t p0; p0 = points[];
k = ;
for (i=; i<n; ++i) {
if (points[i].x<p0.x || (points[i].x==p0.x && points[i].y<p0.y)) {
p0 = points[i];
k = i;
}
} points[k] = points[];
points[] = p0;
sort(points+, points+n, comp); stack[] = points[];
stack[] = points[];
stack[] = points[];
top = ;
for (i=; i<n; ++i) {
while (cross(stack[top-], stack[top], points[i])<= && top>)
--top;
stack[++top] = points[i];
}
stack[++top] = p0;
for (i=; i<=top; ++i)
ret += Length(stack[i-], stack[i]); return ret;
} int main() {
int t;
int i, j, k, tmp;
double l, ans; #ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
#endif scanf("%d", &t);
while (t--) {
scanf("%d %lf", &n, &l);
for (i=; i<n; ++i)
scanf("%lf %lf", &points[i].x, &points[i].y);
ans = Graham();
ans += PI * (l+l);
printf("%.0lf\n", ans);
if (t)
printf("\n");
} return ;
}

【HDOJ】1348 Wall的更多相关文章

  1. 【HDOJ】1484 Basic wall maze

    BFS. /* 1484 */ #include <iostream> #include <queue> #include <string> #include &l ...

  2. 【HDOJ】4729 An Easy Problem for Elfness

    其实是求树上的路径间的数据第K大的题目.果断主席树 + LCA.初始流量是这条路径上的最小值.若a<=b,显然直接为s->t建立pipe可以使流量最优:否则,对[0, 10**4]二分得到 ...

  3. 【POJ】1113 Wall(凸包)

    http://poj.org/problem?id=1113 答案是凸包周长+半径为l的圆的周长... 证明?这是个坑.. #include <cstdio> #include <c ...

  4. 【HDOJ】【3506】Monkey Party

    DP/四边形不等式 裸题环形石子合并…… 拆环为链即可 //HDOJ 3506 #include<cmath> #include<vector> #include<cst ...

  5. 【HDOJ】【3516】Tree Construction

    DP/四边形不等式 这题跟石子合并有点像…… dp[i][j]为将第 i 个点开始的 j 个点合并的最小代价. 易知有 dp[i][j]=min{dp[i][j] , dp[i][k-i+1]+dp[ ...

  6. 【HDOJ】【3480】Division

    DP/四边形不等式 要求将一个可重集S分成M个子集,求子集的极差的平方和最小是多少…… 首先我们先将这N个数排序,容易想到每个自己都对应着这个有序数组中的一段……而不会是互相穿插着= =因为交换一下明 ...

  7. 【HDOJ】【2829】Lawrence

    DP/四边形不等式 做过POJ 1739 邮局那道题后就很容易写出动规方程: dp[i][j]=min{dp[i-1][k]+w[k+1][j]}(表示前 j 个点分成 i 块的最小代价) $w(l, ...

  8. 【HDOJ】【3415】Max Sum of Max-K-sub-sequence

    DP/单调队列优化 呃……环形链求最大k子段和. 首先拆环为链求前缀和…… 然后单调队列吧<_<,裸题没啥好说的…… WA:为毛手写队列就会挂,必须用STL的deque?(写挂自己弱……s ...

  9. 【HDOJ】【3530】Subsequence

    DP/单调队列优化 题解:http://www.cnblogs.com/yymore/archive/2011/06/22/2087553.html 引用: 首先我们要明确几件事情 1.假设我们现在知 ...

随机推荐

  1. android之interpolator的用法详解

    Android:interpolator Interpolator 被用来修饰动画效果,定义动画的变化率,可以使存在的动画效果accelerated(加速),decelerated(减速),repea ...

  2. Android-Socket传输 GPRS网络

    手机使用GPRS网络与server进行Socket通信,代码下载地址:http://download.csdn.net/detail/wu20093346/7768481 用UDP协议与Socket调 ...

  3. Queueing in the Linux Network Stack !!!!!!!!!!!!!!!

    https://www.coverfire.com/articles/queueing-in-the-linux-network-stack/ Queueing in the Linux Networ ...

  4. 关于C++构造函数的FAQ

    [1] 构造函数是用来干什么的? 构造函数构建类的对象,初始化类变量,分配资源(内存.文件.信号量.套接口等等) [2] List x; 和 List x();有什么不同? 前一个是定义List的一个 ...

  5. nginx url 重写 [转]

    本文转自 http://www.jbxue.com/article/2187.html 本文介绍nginx URL重写的相关知识,包括301重定向的内容等,希望对大家有所帮助. nginx rewri ...

  6. Linux FTP YUM源搭建简单记录

    1. 挂载iso镜像,进入Packages目录下安装FTP服务 #rpm -ivh vsftpd-3.0.2-10.el7.x86_64.rpm 2. 修改vsftpd配置文件如下 [root@rus ...

  7. The requested URL ***** was not found on this serve

    Wamp的Alias具体是干什么用的,后面要研究一下!!!! 我是之前创建了一个站点用Alias,后来把站点文件移到了www下后,除了首页都访问不了了.显示“The requested URL *** ...

  8. Volley框架使用(POST)

    需要在MyApplication(继承Application)中配置; public static RequestQueue requestQueue; @Override public void o ...

  9. OpenGL ES 3.0 顶点缓冲区VBO使用

    一般情况下数据都是有CPU从RAM取数据 然后传给GPU去处理,相对于GPU速度要慢一些. 使用VBO技术 可以把数据存储到GPU的内存空间中,这样GPU可以直接从GPU的内存中取得数据进行处理 速度 ...

  10. 017_bcp_bulk_openrowset

    017_bcp_bulk_openrowset --bcp*********************************************************************** ...