题意:给定 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. bzoj2561: 最小生成树

    如果出现在最小生成树上,那么此时比该边权值小的边无法连通uv.据此跑最小割(最大流)即可. #include<cstdio> #include<cstring> #includ ...

  2. LeetCode Swap Nodes in Pairs 交换结点对(单链表)

    题意:给一个单链表,将其每两个结点交换,只改尾指针,不改元素值. 思路:迭代法和递归法都容易写,就写个递归的了. 4ms /** * Definition for singly-linked list ...

  3. POJ 1573 Robot Motion

    Robot Motion Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12978   Accepted: 6290 Des ...

  4. OpenGL开发时,fatal error C1083: 无法打开包括文件:“gl\glut.h”: No such file or directory

    本人使用的是vs2012,编写一个简单的opengl程序,运行的时候总是提示: fatal error C1083: 无法打开包括文件:“gl/glut.h”: No such file or dir ...

  5. java 读取TXT文件的方法

    java读取txt文件内容.可以作如下理解: 首先获得一个文件句柄.File file = new File(); file即为文件句柄.两人之间连通电话网络了.接下来可以开始打电话了. 通过这条线路 ...

  6. [OFBiz]开发 四

    1.在几个已安装的应用模块中,资产管理模块,是最简单的,可以从这个开始入手.E:\eclipse-SDK-3.7.1-win32\ofbiz\apache-ofbiz-10.04\specialpur ...

  7. linux常用命令之--磁盘管理命令

    linux的磁盘管理命令 1.查看磁盘空间 df:用于显示磁盘空间的使用情况 其命令格式如下: df [-option] 常用参数: -i:使用inodes显示结果 -k:使用KBytes显示结果 - ...

  8. 向Window BCD 文件添加VHD开机启动项的相关笔记

    ******************************************************************************** * BCD_YE_MIN文件说明:(精 ...

  9. TRANSLATE

    语法格式: TRANSLATE(expr, from_string, to_string) 示例如下: SELECT TRANSLATE('ab 你好 bcdefg', 'abcdefg', '123 ...

  10. 【暑假】[实用数据结构]UVa11995 I Can Guess the Data Structure!

    UVa11995  I Can Guess the Data Structure! 思路:边读边模拟,注意empty的判断! 代码如下: #include<iostream> #inclu ...