题意:给定 n 个点,让你用最长的周长把它们严格包围起来,边长只能用小格子边长或者是小格子对角线。

析:先把每个点的上下左右都放到一个集合中,然后求出一个凸包,然后先边长转成题目的方式,也好转两个点的最小的*根号2加上两者差*1.

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <stack>
using namespace std ; typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-10;
const int maxn = 4e5 + 5;
const int mod = 1e9 + 7;
const double sqrt2 = sqrt(2.0);
const char *mark = "+-*";
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
int n, m;
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
} inline double add(double a, double b){
if(abs(a+b) < eps * (abs(a) + abs(b))) return 0;
return a + b;
}
struct Point{
double x, y;
Point(){ }
Point(double xx, double yy) : x(xx), y(yy) { }
Point operator + (Point p){
return Point(add(x, p.x), add(y, p.y));
}
Point operator - (Point p){
return Point(add(x, -p.x), add(y, -p.y));
}
double dot(Point p){
return add(x*p.x, -y*p.y);
}
double det(Point p){
return add(x*p.y, -y*p.x);
}
}; bool cmp(const Point &lhs, const Point &rhs){
if(lhs.x != rhs.x) return lhs.x < rhs.x;
return lhs.y < rhs.y;
} vector<Point> convex_hull(Point *ps, int n){
sort(ps, ps+n, cmp);
int k = 0;
vector<Point> qs(n*2);
for(int i = 0; i < n; ++i){
while(k > 1 && (qs[k-1] - qs[k-2]).det(ps[i] - qs[k-1]) <= 0) --k;
qs[k++] = ps[i];
}
for(int i = n-2, t = k; i >= 0; --i){
while(k > t && (qs[k-1]-qs[k-2]).det(ps[i]-qs[k-1]) <= 0) --k;
qs[k++] = ps[i];
}
qs.resize(k-1);
return qs;
} double dist(Point p, Point q){
return (p-q).dot(p-q);
} Point ps[maxn]; double solve(int n){
vector<Point> qs = convex_hull(ps, n);
double ans = 0;
int m = qs.size();
for(int i = 0; i < m; ++i){
int x = abs(qs[i].x - qs[(i+1)%m].x);
int y = abs(qs[i].y - qs[(i+1)%m].y);
ans += abs(x-y);
ans += 1.0*min(x, y) * sqrt2;
}
return ans;
} int main(){
while(scanf("%d", &n) == 1){
int cnt = 0;
for(int i = 0; i < n; ++i){
double x, y;
scanf("%lf %lf", &x, &y);
ps[cnt++] = Point(x+1, y);
ps[cnt++] = Point(x, y+1);
ps[cnt++] = Point(x, y-1);
ps[cnt++] = Point(x-1, y);
}
printf("%.6f\n", solve(cnt));
}
return 0;
}

  

UVaLive 6859 Points (几何,凸包)的更多相关文章

  1. UVALive 6859 Points (凸包)

    Points 题目链接: http://acm.hust.edu.cn/vjudge/contest/130303#problem/E Description http://7xjob4.com1.z ...

  2. UVALive 6859——凸包&&周长

    题目 链接 题意:在一个网格图上,给出$n$个点的坐标,用一个多边形包围这些点(不能接触,且多边形的边只能是对角线或直线),求多边形的最小周长. 分析 对于每个点,我们考虑与之相邻的4个点.一共由 $ ...

  3. POJ 3805 Separate Points (判断凸包相交)

    题目链接:POJ 3805 Problem Description Numbers of black and white points are placed on a plane. Let's ima ...

  4. UVALive 2453 Wall (凸包)

    题意:给你一个多边形的城堡(多个点),使用最短周长的城墙将这个城堡围起来并保证城墙的每个点到城堡上的每个点的距离都不小于l 题解:因为两点间的直线一定比折线短,所以这样做 先使用所有点求得一个凸包,接 ...

  5. HDU 4946 Area of Mushroom (几何凸包)

    题目链接 题意:给定n个人,每个人有一个速度v方向任意.如果平面中存在一个点只有某个人到达的时间最短(即没有人比这个人到的时间更短或相同),那么我们定义这个店归这个人管辖,现在问这些人中哪些人的管辖范 ...

  6. UVA 10173 (几何凸包)

    判断矩形能包围点集的最小面积:凸包 #include <iostream> #include <cmath> #include <cstdio> #include ...

  7. UVA 11355 Cool Points(几何)

    Cool Points We have a circle of radius R and several line segments situated within the circumference ...

  8. 简单几何(凸包+多边形面积) POJ 3348 Cows

    题目传送门 题意:求凸包 + (int)求面积 / 50 /************************************************ * Author :Running_Tim ...

  9. 简单几何(凸包+枚举) POJ 1873 The Fortified Forest

    题目传送门 题意:砍掉一些树,用它们做成篱笆把剩余的树围起来,问最小价值 分析:数据量不大,考虑状态压缩暴力枚举,求凸包以及计算凸包长度.虽说是水题,毕竟是final,自己状压的最大情况写错了,而且忘 ...

随机推荐

  1. linux delete files older than 3 days

    4 down vote accepted This is easy enough (although note that this goes by a modification time more t ...

  2. hdu 4970 Killing Monsters (思维 暴力)

    题目链接 题意: 有n座塔,每座塔的攻击范围为[l,r],攻击力为d,有k个怪兽从这些塔前面经过,第i只怪兽初始的生命力为hp,出现的位置为x,终点为第n个格子.问最后有多少只怪兽还活着. 分析: 这 ...

  3. 4010: [HNOI2015]菜肴制作

    拓扑排序+堆. 转自popoqqq神犇. 反向建图跑拓扑排序然后逆序输出. 为什么不能正的来呢,因为不知道选当前菜要先制作哪种菜. 逆序过来跑拓扑的话,也能保证满足限制条件编号小的在前面. 题外话:我 ...

  4. UVa 1025 (动态规划) A Spy in the Metro

    题意: 有线性的n个车站,从左到右编号分别为1~n.有M1辆车从第一站开始向右开,有M2辆车从第二站开始向左开.在0时刻主人公从第1站出发,要在T时刻回见车站n 的一个间谍(忽略主人公的换乘时间).输 ...

  5. UVa 10129 (并查集 + 欧拉路径) Play on Words

    题意: 有n个由小写字母的单词,要求判断是否存在某种排列使得相邻的两个单词,前一个单词末字母与后一个单词首字母相同. 分析: 将单词的两个字母看做节点,则一个单词可以看做一条有向边.那么题中所求的排列 ...

  6. Jqgrid入门-Jqgrid设置二级表头(六)

    上一章已经说明了Jqgrid结合Struts2+json展示数据,这一章主要探讨Jqgrid如何设置二级表头,类似这样的效果.如:           要实现这个功能,其实也不难.通过Jqgrid的s ...

  7. Java Web编程的主要组件技术——Struts的高级功能

    参考书籍:<J2EE开源编程精要15讲> Struts对国际化的支持 "国际化"(I18N)指一个应用程序在运行时能根据客户端请求所来的国家/地区.语言的不同显示不同的 ...

  8. How to delete a team project from Team Foundation Service (tfs.visualstudio.com)

    C:\project>tfsdeleteproject /collection:https://buckh-test2.visualstudio.com/DefaultCollection Te ...

  9. webapp调试工具weinre的使用

    在设计师与前端开发人员的努力下,一个WebApp出炉了,可是测试人员说了一堆的问题:某某机型下页面表现不一致,某某系统下页面如何如何,某某 系统浏览器下页面怎么怎么滴.看着满满的测试汇总文档,我们曾经 ...

  10. 批量添加-fno-objc-arc

    http://syxiaqj.github.io/2014/02/28/bee-learning-1/ 4.批量添加-fno-objc-arc 因为BeeFramework是一个非RAC的框架,现在X ...