首页 > 其他分享 >poj 1113 Wall-----凸包

poj 1113 Wall-----凸包

时间:2023-09-12 12:01:10浏览次数:30  
标签:node Wall double 100100 int 1113 ----- ans include


凸包问题。

先按 x坐标排序,x一样的按 y 排序。

取p【0】为开始点,每个点与开始点相连,按x轴正方向,每条线段与x轴的夹角 由小到大排序。

然后选点求距离。。。

本题求凸包的边长+以L为半径的园的周长。


//自己的凸包模板
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
#define pi acos(-1.0)
#define N 100100
#define inf 0x3f3f3f3f

struct node
{
	double x,y;
}p[100100];
int s[100100];
double dis(node a,node b)
{
	return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
double chaji(node a,node b)
{
	return a.x*b.y-a.y*b.x;
}
bool cmp(node a,node b)
{
	a.x-=p[0].x,a.y-=p[0].y;
	b.x-=p[0].x,b.y-=p[0].y;
	if(chaji(a,b)==0)
		return a.x<b.x;
	return (chaji(a,b)>0);
}
int main()
{
	int n,r;
	while(~scanf("%d%d",&n,&r))
	{
		int i,j,k,t=-1;
		for(i=0;i<n;++i){
			scanf("%lf%lf",&p[i].x,&p[i].y);
			if(t==-1 || p[i].x<p[t].x)
				t=i;
			else if(p[i].x==p[t].x && p[i].y<p[t].y)
				t=i;
		}
		if(n==1)
		{
			printf("%.2lf\n",2*pi*r);
		}
		else if(n==2)
		{
			printf("%.2lf\n",2*pi*r+dis(p[0],p[1])*2);
		}
		else
		{
			node tt;
			tt=p[t],p[t]=p[0],p[0]=tt;
			sort(p+1,p+n,cmp);
			int ans=0;
			s[0]=0,s[1]=1,ans+=2;
			for(i=2;i<n;i++)
			{
				if(ans<=1)
					s[ans]=i,ans++;
				else
				{
					node a,b;
					k=ans;
					a.x=p[s[k-2]].x-p[s[k-1]].x;
					a.y=p[s[k-2]].y-p[s[k-1]].y;
					b.x=p[s[k-1]].x-p[i].x;
					b.y=p[s[k-1]].y-p[i].y;
					if(chaji(a,b)>=0)
						s[ans]=i,ans++;
					else{
						ans--;
						i--;
					}
				}
			}
			double sum=0;
			for(i=1;i<ans;i++)
				sum+=dis(p[s[i]],p[s[i-1]]);
			sum+=dis(p[s[ans-1]],p[s[0]]);
			printf("%.0lf\n",sum+2*pi*r);
		}
	}
}




标签:node,Wall,double,100100,int,1113,-----,ans,include
From: https://blog.51cto.com/u_16244339/7444179

相关文章

  • hdu 1372 Knight Moves 骑士的移动 bfs--马走日
    #include<stdio.h>#include<string.h>#include<queue>usingnamespacestd;charss[3],ee[3];intx1,y1,x2,y2;structpos{intx,y,step;}sta,end;intf[10][10];intdir[8][2]={1,2,1,-2,-1,2,-1,-2,2,1,2,-1,-2,1,-2,-1};boolfan......
  • Redis - 出现ERROR:WRONGTYPE Operation against a key holding the wrong kind of val
    原因:用的方法与redis服务器中存储数据的类型存在冲突。比如:有一个key的数据存储的是list类型的,但使用redis执行数据操作的时候却使用了非list的操作方法。 对一个Redis键执行不兼容的操作,这个错误通常发生在以下情况:1、类型不匹配:试图执行的操作与键存储的数据类型不匹配。例......
  • vue-i18n
    https://kazupon.github.io/vue-i18n/zh/introduction.html开始如果使用模块系统(例如通过vue-cli),则需要导入Vue和VueI18n,然后调用Vue.use(VueI18n)。格式化在某些情况下,你可能希望将翻译呈现为HTML信息而不是静态字符串。在你的网站上动态插入任意HTML可能......
  • Cisco NX-OS 10.4(1)F 发布 - 网络操作系统软件
    CiscoNX-OS10.4(1)F发布-网络操作系统软件CiscoNX-OSSoftwareRelease10.4(1)F-网络操作系统软件请访问原文链接:https://sysin.org/blog/cisco-nx-os-10/,查看最新版。原创作品,转载请保留出处。作者主页:sysin.orgCiscoNX-OSCiscoNX-OS操作系统助力网络紧跟业务......
  • spfa---模板
    spfa模板#include<stdio.h>#include<string.h>#include<stdlib.h>#include<queue>usingnamespacestd;#defineV1010//点的个数#defineE4020//变的个数*2(双向边)#defineINF0x3f3f3f3fstructnode{ inta,b,len;}p[E];intnex[E];intfirs......
  • 矩阵快速幂--模板
    http://acm.bit.edu.cn/mod/programming/view.php?id=670TheLittleArchitectII#include<stdio.h>#include<string.h>//dp方程:f[n]=3*f[n-1]+3*f[n-2]-f[n-3];//矩阵快速幂。。模板//构造矩阵//310//301//-100structnode{ longlonga[3][3];};lon......
  • 最小生成树---模板
    最基础模板#include<stdio.h>#include<string.h>#include<algorithm>usingnamespacestd;#defineV110//点的个数#defineE5100//边的个数intparent[V];introot(intp){ if(parent[p]==-1)returnp; elsereturnparent[p]=root(parent[p]);}void......
  • 欧拉函数--模板
    欧拉函数--模板//求1..n-1中与n互质的数的个数inteular(intn){ intret=1,i; for(i=2;i*i<=n;i++) if(n%i==0){ n/=i,ret*=i-1; while(n%i==0) n/=i,ret*=i; } if(n>1) ret*=n-1; returnret;}......
  • Python - 接口自动化(Requests)
    1、requests简介如果想用python做接口测试,我们首先有不得不了解和学习的模块。它就是python的第三方模块:Requests。虽然Python内置有urllib模块用于访问网络资源。但是,它用起来比较麻烦,而且,缺少很多实用的高级功能。所以呢更好的方案是使用requests。它也是目前应用最广泛、最......
  • 二叉树 遍历 hdu-1710-Binary Tree Traversals
    给出二叉树的前序遍历和中序遍历,求后序遍历。。 算法:由前序遍历的第一个元素可确定左、右子树的根节点,参照中序遍历又可进一步确定子树的左、右子树元素。如此递归地参照两个遍历序列,最终构造出二叉树。 由前序和中序结果求后序遍历结果树的遍历: 给你一棵树的先......