【#define PI acos(-1.0)】【非凸包】poj 2365 Rope

简介:

这道题按顺序加起来就OK了。。。

唯一要注意的就是当N==1的时候,只输出一个钉子的周长就ok了。。。特殊处理下就可以了

看discuss,这道题好多人用凸包做,反而错,我现在标记一下,之后用凸包也试试。。。

另外就是#define PI acos(-1.0),可以定义π


#include <stdio.h>
#include<math.h>

#define PI acos(-1.0)

int main()
{
	int N;
	scanf("%d",&N);

	double R;
	scanf("%lf",&R);
	
	double x,y;
	double xx,yy;
	double firstX,firstY;
	scanf("%lf%lf",&xx,&yy);


	if (N==1)
	{
		printf("%.2lf\n",2*PI*R);
		return 0;
	}

	firstX=xx;
	firstY=yy;

	int i;
	double lenth=0;
	double tmpX,tmpY;
	for(i=1;i<N;i++)
	{
		scanf("%lf%lf",&x,&y);
		tmpX=x-xx;
		tmpY=y-yy;
		lenth+=sqrt(tmpX*tmpX+tmpY*tmpY);

		xx=x;
		yy=y;
	}

	tmpX=x-firstX;
	tmpY=y-firstY;
	lenth+=sqrt(tmpX*tmpX+tmpY*tmpY);

	lenth+=2*PI*R;

	printf("%.2lf\n",lenth);

	return 0;
}


相关文章
|
3月前
PTA-圆周率PI的近似值
圆周率PI的近似值
22 1
|
9月前
uva167 The Sultan's Successors
uva167 The Sultan's Successors
32 0
|
12月前
零基础VB教程061期:常用数学函数第一节 弧度/ abs/sin/cos/tan/atn/exp/log等
零基础VB教程061期:常用数学函数第一节 弧度/ abs/sin/cos/tan/atn/exp/log等
POJ-2389,Bull Math(大数乘法)
POJ-2389,Bull Math(大数乘法)
|
机器学习/深度学习
POJ 1775 (ZOJ 2358) Sum of Factorials
POJ 1775 (ZOJ 2358) Sum of Factorials
122 0
【PTA】7-6 求最大公约数 (40point(s))
【PTA】7-6 求最大公约数 (40point(s))
167 0
|
Python
sqrt函数
import numpy as np B = np.arange(3) print (B) print (np.sqrt(B)) #求平方根 知识在于点滴积累
970 0
|
BI 人工智能