UVaLive 6859 Points (几何,凸包)
题意:给定 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 (几何,凸包)的更多相关文章
- UVALive 6859 Points (凸包)
Points 题目链接: http://acm.hust.edu.cn/vjudge/contest/130303#problem/E Description http://7xjob4.com1.z ...
- UVALive 6859——凸包&&周长
题目 链接 题意:在一个网格图上,给出$n$个点的坐标,用一个多边形包围这些点(不能接触,且多边形的边只能是对角线或直线),求多边形的最小周长. 分析 对于每个点,我们考虑与之相邻的4个点.一共由 $ ...
- POJ 3805 Separate Points (判断凸包相交)
题目链接:POJ 3805 Problem Description Numbers of black and white points are placed on a plane. Let's ima ...
- UVALive 2453 Wall (凸包)
题意:给你一个多边形的城堡(多个点),使用最短周长的城墙将这个城堡围起来并保证城墙的每个点到城堡上的每个点的距离都不小于l 题解:因为两点间的直线一定比折线短,所以这样做 先使用所有点求得一个凸包,接 ...
- HDU 4946 Area of Mushroom (几何凸包)
题目链接 题意:给定n个人,每个人有一个速度v方向任意.如果平面中存在一个点只有某个人到达的时间最短(即没有人比这个人到的时间更短或相同),那么我们定义这个店归这个人管辖,现在问这些人中哪些人的管辖范 ...
- UVA 10173 (几何凸包)
判断矩形能包围点集的最小面积:凸包 #include <iostream> #include <cmath> #include <cstdio> #include ...
- UVA 11355 Cool Points(几何)
Cool Points We have a circle of radius R and several line segments situated within the circumference ...
- 简单几何(凸包+多边形面积) POJ 3348 Cows
题目传送门 题意:求凸包 + (int)求面积 / 50 /************************************************ * Author :Running_Tim ...
- 简单几何(凸包+枚举) POJ 1873 The Fortified Forest
题目传送门 题意:砍掉一些树,用它们做成篱笆把剩余的树围起来,问最小价值 分析:数据量不大,考虑状态压缩暴力枚举,求凸包以及计算凸包长度.虽说是水题,毕竟是final,自己状压的最大情况写错了,而且忘 ...
随机推荐
- Android_PendingIntent的使用
PendingIntent介绍 PendingIntent可以看作是对Intent的一个封装,但它不是立刻执行某个行为,而是满足某些条件或触发某些事件后才执行指定的行为. PendingInt ...
- 无法连接到SQL Server 2008 R2
服务器环境: 操作系统 名称: Microsoft Windows Server 2008 R2 Enterprise 版本: 6.1.7601 服务包: Ser ...
- hdu 4607 Park Visit(树上最长链)
求树上最长链:两遍搜索. 第一次从树上任意点开始,最远点必然是某一条最长链上的端点u. 第二次从u开始,最远点即该最长链的另一端点. 先在最长链上走,不足再去走支链. 把询问数m错打成n,狠狠wa了一 ...
- 物联网操作系统HelloX V1.78测试版正式发布
经过HelloX开发团队近四个月的努力,在HelloX V1.77版本基础上,增加许多功能特性,并对V1.77版本的一些特性进行了进一步优化之后,正式形成HelloX V1.78测试版本,经相对充分的 ...
- [转载]ios入门篇 -hello Word(1)
温馨提示:,如果您使用移动终端阅读本篇文章,请连接wifi的情况下阅读,里面有大量图片,以免造成您不必要的损失. 潜水博客园很多年,闲来无事,聊一下自己的经历,语文不好(如有什么错别字,请您在下评 ...
- HDU 5881 Tea
Tea Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- Java SE 6 新特性: Java DB 和 JDBC 4.0
http://www.ibm.com/developerworks/cn/java/j-lo-jse65/index.html 长久以来,由于大量(甚至几乎所有)的 Java 应用都依赖于数据库,如何 ...
- Delphi 712操作word
//导出Wordprocedure TFrm_Computing.ExportWord;var wordApp, WordDoc, WrdSelection, wrdtable, wrdtable1, ...
- NSThread 多线程相关
1.下面的代码,有2点需要注意,1>就是 就是thread:所传得参数,这里传得的是nsarray 当然也可以传其他的类型.2> [self performSelectorOnMainTh ...
- DataSet DataTable操作
DataSet ds = new DataSet(); DataTable dt = new DataTable("OrderList"); ...