1.poj1113 Wall

题目:http://poj.org/problem?id=1113

题意:用一条线把若干个点包起来,并且线距离任何一个点的距离都不小于r。求这条线的最小距离是多少?

分析:这道题的答案是凸包周长加上一个圆周长,即包围凸包的一个圆角多边形,但是没弄明白那些圆角加起来为什么恰好是一个圆。每个圆角是以凸包对应的顶点为圆心,给定的L为半径,与相邻两条边的切点之间的一段圆弧。每个圆弧的两条半径夹角与对应的凸包的内角互补。假设凸包有n条边,则所有圆弧角之和为180°*n-180°*(n-2)=360°。故,围墙周长为=n条平行于凸包的线段+n条圆弧的长度=凸包周长+围墙离城堡距离L为半径的圆周长。

 #include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int maxn=;
const double eps=1e-;
const double pi=acos(-1.0);
inline double sqr(double x){return x*x;}
int sgn(double x){
if (fabs(x)<eps) return ;
if (x<) return -;
return ;
}
struct point{
double x,y;
point(){}
point(double _x,double _y):x(_x),y(_y){}
//判断两点相同
bool operator ==(const point &b) const{
return sgn(x-b.x)== && sgn(y-b.y)==;
}
//
point operator -(const point &b) const{
return point(x-b.x,y-b.y);
}
//叉积
double operator ^(const point &b) const{
return x*b.y-y*b.x;
}
//点积
double operator *(const point &b) const{
return x*b.x+y*b.y;
}
//重载小于号 (求最左下角的点
bool operator <(const point &b)const{
return sgn(x-b.x)== ? sgn(y-b.y)< : x<b.x;
}
};
struct line{
point s,e;
line(){}
line(point _s,point _e):s(_s),e(_e){}
};
double dis(point a,point b){
return sqrt(sqr(a.x-b.x)+sqr(a.y-b.y));
}
struct polygon{
int n;
point p[maxn];
line l[maxn];
void add(point q){
p[n++]=q;
}
void getline(){
for (int i=;i<n;i++)
l[i]=line(p[i],p[(i+)%n]);
}
struct cmp{
point p;
cmp(const point &p0):p(p0){}
bool operator ()(const point &aa,const point &bb){
point a=aa,b=bb;
int d=sgn((a-p)^(b-p));
if (d==){
return sgn(dis(a,p)-dis(b,p))<;
}
return d>;
}
};
//极角排序 先找到左下角的点
//重载好point的'<'
void norm(){
point mi=p[];
for (int i=;i<n;i++) mi=min(mi,p[i]);
sort(p,p+n,cmp(mi));
}
//得到凸包,点编号为0--n-1
void Graham(polygon &convex){
norm();
int &top=convex.n;
top=;
if (n==){
top=; convex.p[]=p[]; return ;
}
if (n==){
top=; convex.p[]=p[]; convex.p[]=p[];
if (convex.p[]==convex.p[]) top--;
return ;
}
convex.p[]=p[]; convex.p[]=p[]; top=;
for (int i=;i<n;i++){
while (top> && sgn((convex.p[top-]-convex.p[top-])^(p[i]-convex.p[top-]))<=) top--;
convex.p[top++]=p[i];
}
if (convex.n== && (convex.p[]==convex.p[])) convex.n--;
}
};
polygon C;
int main(){
int n,L; cin >> n >> L;
double x,y;
for (int i=;i<n;i++){
cin >> x >> y;
C.add(point(x,y));
}
polygon ans;
C.Graham(ans);
ans.getline();
double res=;
for (int i=;i<ans.n;i++) res+=dis(ans.l[i].s,ans.l[i].e);
res+=*pi*L;
printf("%d\n",(int)(res+0.5));
return ;
}

poj1113

(为了套板子,写的很繁琐)

2.poj2007 Scrambled Polygon

题目:http://poj.org/problem?id=2007

题意:求一个凸多边形的凸包。要求起始点为输入的第一个点。

分析:rt。

 #include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
const double eps=1e-;
const int maxn=;
inline double sqr(int x){return x*x*1.0;}
int sgn(double x){
if (fabs(x)<eps) return ;
if (x<) return -;
return ;
}
struct point{
int x,y;
point(){}
point(int _x,int _y):x(_x),y(_y){}
bool operator ==(const point &b)const{
return (x==b.x && y==b.y);
}
point operator -(const point &b)const{
return point(x-b.x,y-b.y);
}
int operator ^(const point &b)const{
return x*b.y-y*b.x;
}
int operator *(const point &b)const{
return x*b.x+y*b.y;
}
//重载小于号 (求最左下角的点
bool operator <(const point &b)const{
return sgn((x-b.x)*1.0)== ? sgn((y-b.y)*1.0)< : x<b.x;
}
};
double dis(point a,point b){
return sqrt(sqr(a.x-b.x)+sqr(a.y-b.y));
}
struct polygon{
int n;
point p[maxn];
void add(point q){
p[n++]=q;
}
struct cmp{
point p;
cmp(const point &p0):p(p0){}
bool operator ()(const point &aa,const point &bb){
point a=aa,b=bb;
int k=(a-p)^(b-p);int d;
if (k==) d=;else if (k<) d=-; else d=;
if (d==){
return sgn(dis(a,p)-dis(b,p))<;
}
return d>;
}
};
//极角排序 先找到左下角的点
//重载好point的'<'
void norm(){
point mi=p[];
for (int i=;i<n;i++) mi=min(mi,p[i]);
sort(p,p+n,cmp(mi));
}
//得到凸包,点编号为0--n-1
void Graham(polygon &convex){
norm();
int &top=convex.n;
top=;
if (n==){
top=; convex.p[]=p[]; return ;
}
if (n==){
top=; convex.p[]=p[]; convex.p[]=p[];
if (convex.p[]==convex.p[]) top--;
return ;
}
convex.p[]=p[]; convex.p[]=p[]; top=;
for (int i=;i<n;i++){
while (top> && sgn(((convex.p[top-]-convex.p[top-])^(p[i]-convex.p[top-]))*1.0)<=) top--;
convex.p[top++]=p[i];
}
if (convex.n== && (convex.p[]==convex.p[])) convex.n--;
}
};
polygon C;
int main(){
int x,y; point p;
C.n=;
cin >> x >> y; p=point(x,y); C.add(p);
while (cin >> x >> y) C.add(point(x,y));
polygon ans;
C.Graham(ans); int k;
for (int i=;i<ans.n;i++) if (ans.p[i]==p){k=i;break;}
for (int i=;i<ans.n;i++){
printf("(%d,%d)\n",ans.p[(k+i)%ans.n].x,ans.p[(k+i)%ans.n].y);
}
return ;
}

poj2007

3.poj1228

  题目:http://poj.org/problem?id=1228

题意:输入一个凸包上的点(没有凸包内部的点,要么是凸包顶点,要么是凸包边上的点),判断这个凸包是否稳定。所谓稳定就是判断能不能在原有凸包上加点。

分析:问凸包是否稳定。

 #include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const double eps=1e-;
const int maxn=;
int sgn(double x){
if (fabs(x)<eps) return ;
if (x<) return -;
return ;
}
struct point{
double x,y;
point(){}
point(double _x,double _y):x(_x),y(_y){}
point operator -(const point &b)const{
return point(x-b.x,y-b.y);
}
double operator ^(const point &b)const{
return x*b.y-y*b.x;
}
}p[maxn],pp[maxn];
bool cmp(point a,point b) {return a.x < b.x || (a.x == b.x && a.y < b.y);}
int convexhull(point p[],int n,point pp[]){
sort(p,p+n,cmp);
int m=;
for (int i=;i<n;i++){
while (m> && ((pp[m-]-pp[m-])^(p[i]-pp[m-]))<) m--;
pp[m++]=p[i];
}
int k=m;
for (int i=n-;i>=;i--){
while (m>k && ((pp[m-]-pp[m-])^(p[i]-pp[m-]))<) m--;
pp[m++]=p[i];
}
return m-;
}
bool check(point p[],int n){
for (int i=;i<n-;i++){
if (((p[i-]-p[i])^(p[i+]-p[i]))!= &&
((p[i]-p[i+])^(p[i+]-p[i+]))!=) return false; //保证至少有三个点在同一条边上
}
return true;
}
int main(){
int t,n; double x,y; cin >> t;
while (t--){
cin >> n;
for (int i=;i<n;i++) cin >> p[i].x >> p[i].y;
if (n<){cout << "NO\n";continue;}
int cnt=convexhull(p,n,pp);
if (check(pp,cnt)) cout << "YES\n"; else cout << "NO\n";
}
return ;
}

poj1228

4

5.poj3348 Cows

题目:http://poj.org/problem?id=3348

题意:给出一些点圈出一个最大面积每50平方养一头牛问最多能养多少牛。

分析:凸包+多边形面积。

 #include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int maxn=;
inline int sqr(int x){return x*x;}
struct point{
int x,y;
point(){}
point(int _x,int _y):x(_x),y(_y){}
//判断两点相同
bool operator ==(const point &b) const{
return x-b.x== && y-b.y==;
}
//
point operator -(const point &b) const{
return point(x-b.x,y-b.y);
}
//叉积
int operator ^(const point &b) const{
return x*b.y-y*b.x;
}
//点积
int operator *(const point &b) const{
return x*b.x+y*b.y;
}
//重载小于号 (求最左下角的点
bool operator <(const point &b)const{
return x-b.x==?y-b.y<:x<b.x;
}
};
struct line{
point s,e;
line(){}
line(point _s,point _e):s(_s),e(_e){}
};
int dis(point a,point b){
return (int)sqrt(1.0*sqr(a.x-b.x)+1.0*sqr(a.y-b.y));
}
struct polygon{
int n;
point p[maxn];
void add(point q){p[n++]=q;}
struct cmp{
point p;
cmp(const point &p0):p(p0){}
bool operator ()(const point &aa,const point &bb){
point a=aa,b=bb;
int k=(a-p)^(b-p);
if (k==){
return dis(a,p)-dis(b,p)<;
}
return k>;
}
};
//极角排序 先找到左下角的点
//重载好point的'<'
void norm(){
point mi=p[];
for (int i=;i<n;i++) mi=min(mi,p[i]);
sort(p,p+n,cmp(mi));
}
//得到凸包,点编号为0--n-1
void Graham(polygon &convex){
norm();
int &top=convex.n;
top=;
if (n==){
top=; convex.p[]=p[]; return ;
}
if (n==){
top=; convex.p[]=p[]; convex.p[]=p[];
if (convex.p[]==convex.p[]) top--;
return ;
}
convex.p[]=p[]; convex.p[]=p[]; top=;
for (int i=;i<n;i++){
while (top> && ((convex.p[top-]-convex.p[top-])^(p[i]-convex.p[top-]))<=) top--;
convex.p[top++]=p[i];
}
if (convex.n== && (convex.p[]==convex.p[])) convex.n--;
}
int getarea(){
int sum=;
for (int i=;i<n;i++) sum+=(p[i]^(p[(i+)%n]));
return sum/;
}
};
polygon C;
int main(){
int n,x,y; cin >> n; C.n=;
for (int i=;i<n;i++){
cin >> x >> y;
C.add(point(x,y));
}
polygon ans; C.Graham(ans);
cout << ans.getarea()/ << endl;
return ;
}

poj3348

6.poj1259/hdoj6219

题意:给出n个点,求出最大面积的凸包且凸包内不包含原点集中的点。

分析:rt。求最大面积空凸包。

 #include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const double eps=1e-;
const int maxn=;
inline double sqr(double x){return x*x;}
int sgn(double x){
if (fabs(x)<eps) return ;
if (x<) return -;
return ;
}
struct point{
double x,y;
point(){}
point(double _x,double _y):x(_x),y(_y){}
//判断两点相同
bool operator ==(const point &b) const{
return sgn(x-b.x)== && sgn(y-b.y)==;
}
//
point operator -(const point &b) const{
return point(x-b.x,y-b.y);
}
//叉积
double operator ^(const point &b) const{
return x*b.y-y*b.x;
}
//点积
double operator *(const point &b) const{
return x*b.x+y*b.y;
}
//重载小于号 (求最左下角的点
bool operator <(const point &b)const{
return sgn(x-b.x)== ? sgn(y-b.y)< : x<b.x;
}
}p[maxn],pp[maxn];
point tmp;
double dp[maxn][maxn];
double empty_convex(point p[],int n,point o){
double ans=;
for (int i=;i<n;i++) for (int j=;j<n;j++) dp[i][j]=;
for (int i=;i<n;i++){
int j=i-;
while (j>= && ((p[i]-o)^(p[j]-o))==) j--;
bool flag=(j==i-);
while (j>=){
int k=j-;
while (k>= && ((p[i]-p[k])^(p[j]-p[k]))>) k--;
double area=fabs((p[i]-o)^(p[j]-o))/2.0;
if (k>=) area+=dp[j][k];
if (flag) dp[i][j]=area;
ans=max(ans,area);
j=k;
}
if (flag){
for (int j=;j<i;j++) dp[i][j]=max(dp[i][j],dp[i][j-]);
}
}
return ans;
}
double dist(point a,point b){
return sqrt((a-b)*(a-b));
}
bool cmp_angle(point a,point b){
double res=(a-tmp)^(b-tmp);
if (res) return res>;
return dist(a,tmp)<dist(b,tmp);
}
double largest_empty_convex(point p[],int n){
double ans=;
for (int i=;i<n;i++){
tmp=p[i];
int cnt=;
for (int j=;j<n;j++){
if (p[j].y>tmp.y || p[j].y==tmp.y && p[j].x>tmp.x) pp[cnt++]=p[j];
}
sort(pp,pp+cnt,cmp_angle); //根据极角排序
ans=max(ans,empty_convex(pp,cnt,tmp));
}
return ans;
}
int main(){
int t,n; cin >> t;
while (t--){
cin >> n;
for (int i=;i<n;i++) cin >> p[i].x >> p[i].y;
double ans=largest_empty_convex(p,n);
printf("%.1f\n",ans);
}
return ;
}

poj1259

【kuangbin专题】计算几何_凸包的更多相关文章

  1. 凸多边形 HRBUST - 1429 计算几何_凸包_未调完

    任选一个点作为起始点,将其他点按与该点连线的极角排序,二分查询点在哪两个射线之间, 并特别判断一下边界即可. Code: #include <cstdio> #include <al ...

  2. hrbustoj 1318:蛋疼的蚂蚁(计算几何,凸包变种,叉积应用)

    蛋疼的蚂蚁 Time Limit: 1000 MS     Memory Limit: 65536 K Total Submit: 39(22 users)    Total Accepted: 26 ...

  3. poj 1696:Space Ant(计算几何,凸包变种,极角排序)

    Space Ant Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2876   Accepted: 1839 Descrip ...

  4. [kuangbin]专题六 最小生成树 题解+总结

    kuangbin专题链接:https://vjudge.net/article/752 kuangbin专题十二 基础DP1 题解+总结:https://www.cnblogs.com/RioTian ...

  5. 【kuangbin专题】计算几何_半平面交

    1.poj3335 Rotating Scoreboard 传送:http://poj.org/problem?id=3335 题意:就是有个球场,球场的形状是个凸多边形,然后观众是坐在多边形的边上的 ...

  6. kuangbin专题十三-基础计算几何

    链接:https://cn.vjudge.net/contest/68968 POJ 2318 TOYS 题意:m个玩具落在n+1个区间,给你玩具的坐标,问每个区间有多少玩具. 思路:叉积的简单应用, ...

  7. 计算几何(凸包):SHTSC 2012 信用卡凸包

    这道题是水题,发现平移某些边,答案就是圆心的凸包+一个圆的周长. 不要忽视精度误差! #include <algorithm> #include <iostream> #inc ...

  8. 【kuangbin专题】计算几何基础

    1.poj2318 TOYS 传送:http://poj.org/problem?id=2318 题意:有m个点落在n+1个区域内.问落在每个区域的个数. 分析:二分查找落在哪个区域内.叉积判断点与线 ...

  9. 【kuangbin】计算几何部分最新模板

    二维几何部分 // `计算几何模板` ; const double inf = 1e20; const double pi = acos(-1.0); ; //`Compares a double t ...

随机推荐

  1. 【Web】Sublime Text 3 连接sftp/ftp(远程服务器)

    在 Win 下常用 Xftp 软件来和远程服务传递文件,但是要是在项目开发的时候频繁的将远程文件拖到本地编辑然后再传回远程服务器,那真是麻烦无比,但是Sublime中SFTP插件,它让这世界美好了许多 ...

  2. 【linux轻松学】修改文件权限

    用chmod修改文件权限,此命令非常重要. 用户范围:u 表示当前用户g 表示当前群组o 除u,g之外的用户和群组a 所有用户和群组 权限代号:r :读,用数字4表示w :写,用数字2表示x :执行, ...

  3. 51.从首页内容跳转到第二个Tabbar控制器(controller)

    TabBarController: 创建TabBar的控制器 注意:在点击的内容方法页面,添加头文件 #import "TabBarController.h" #import &q ...

  4. 存储引擎中MYIASM是什么意思

  5. 2018.11.14 uoj#34. 多项式乘法(ntt)

    传送门 今天学习nttnttntt. 其实递归方法和fftfftfft是完全相同的. 只不过fftfftfft的单位根用的是复数中的东西,而nttnttntt用的是数论里面有相同性质的原根. 代码: ...

  6. Java数据类型的转换

    Java数据类型,从小到大排序 byte ,short ,int ,long ,float, double,char 1.小数据类型转换大的数据类型,自动转换 int a = 3; double b ...

  7. Mysql正常启动之后默认使用的文件

    --basedir=/usr/local/mysql  --datadir=/usr/local/mysql/data  --plugin-dir=/usr/local/mysql/lib/plugi ...

  8. linux上搭建solr(用jetty部署)

    环境搭建:centos7及solr7版本 描述:最新版本的solr内置了jetty容器,可以支持jetty部署,从而不需要发布到tomcat下面 首先同样先在/usr/local/mypackage上 ...

  9. POJ3320 Jessica's Reading Problem 2017-05-25 19:55 38人阅读 评论(0) 收藏

    Jessica's Reading Problem Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12346   Accep ...

  10. ETL化的IOTA架构

    经过这么多年的发展,已经从大数据1.0的BI/Datawarehouse时代,经过大数据2.0的Web/APP过渡,进入到了IOT的大数据3.0时代,而随之而来的是数据架构的变化. ▌Lambda架构 ...