小 Y 的徽章
时间: 1ms 内存:256M
描述:
毕业了,小 Y 想要打造一枚具有纪念意义的徽章送给老师,该徽章是周长为 $l$ 的正 $n$ 边形,现在小 Y 想要知道这枚徽章的面积有多大,你能帮助她解决这个问题么?
输入:
输入只有一行,包含两个整数 $n,l\ (3 \le n \le 50, 1 \le l \le 100000)$,其中 $n$ 代表徽章的边数,$l$ 代表徽章的周长。
输出:
输出小 Y 所打造徽章的大小(结果可能是一个浮点数,如果你的答案与真实值相差 $10^{−4}$ 以内则被认为是正确的)。
示例输入:
3 6
示例输出:
1.7320508076
提示:
参考答案(内存最优[1120]):
#include<stdio.h>
int main()
{
double a = 3.141592653589793;
double s;
int n,l;
scanf("%d %d",&n,&l);
if(n==3)
{
s=(l/n)*(l/n)*1.7320508076/4;
printf("%llf",s);
}
else if(n==4)
{s=(l/n)*(l/n);
printf("%llf",s);}
else
printf("%llf",l/n*a/2/1.7320508076);
return 0;
}
参考答案(时间最优[1]):
#include <stdio.h>
#include <stdlib.h>
#include<math.h>
int main()
{
double PI = 3.141592653589793;
double n,l;
scanf("%lf%lf",&n,&l);
l/=n;
double x;
x=(n-2)*180;
double y;
y=x/n;
y/=2;
double s;
s=n*0.25*l*l*tan(y/180*PI);
printf("%lf\n",s);
return 0;
}
题目和答案均来自于互联网,仅供参考,如有问题请联系管理员修改或删除。