NC50060. 天花乱坠
描述
输入描述
多组测试(不多于100组),每组一行一个整数n( 2 < n <= 100),表示正多边形的边数。
输出描述
对于每组测试,输出一行一个结果,四舍五入保留两位小数。(请用较为简洁的计算方式,以减少误差)
示例1
输入:
3 4 50
输出:
600.00 1365.69 2533863.09
C(clang 3.9) 解法, 执行用时: 4ms, 内存消耗: 476K, 提交时间: 2019-09-05 22:11:05
#include<stdio.h> #include<math.h> #define pi 3.1415926535898 int main() { int n; while(scanf("%d",&n)!=-1) { printf("%.2lf\n",(n*100)/(1-(sin(((n-2)*pi)/(2*n))))); } return 0; }
C++14(g++5.4) 解法, 执行用时: 4ms, 内存消耗: 476K, 提交时间: 2019-07-14 15:51:48
#include<iostream> #include<cstdio> #include<cmath> using namespace std; int main() { int n; double s; while(cin>>n) { s=n*100.0*(1.0/(1.0-cos(M_PI/n))); printf("%.2lf\n",s); } }
C++11(clang++ 3.9) 解法, 执行用时: 4ms, 内存消耗: 480K, 提交时间: 2020-02-26 00:04:35
#include<bits/stdc++.h> using namespace std; const double PI=acos(-1); int main() { double n; double t; while(cin>>n) { t=n*100/(1-cos(PI/n)); printf("%.2lf\n",t); } }
Python3(3.5.2) 解法, 执行用时: 57ms, 内存消耗: 4836K, 提交时间: 2019-07-15 17:02:17
from math import * while True: try: n=int(input()) print('%.2f'%(n*100/(1-cos(pi/n)))) except EOFError: break