Educational Codeforces Round 87 (Rated for Div. 2) 参与排名人数11499,比赛前遇到2次延时,17:05-17:15,17:15-17:20
[codeforces 1354C1] Simple Polygon Embedding 找外接圆
总目录详见https://blog.csdn.net/mrcrack/article/details/103564004
在线测评地址http://codeforces.com/contest/1354/problem/C1
Problem | Lang | Verdict | Time | Memory |
---|---|---|---|---|
C1 - Simple Polygon Embedding | GNU C++17 | Accepted | 30 ms | 3600 KB |
思路如下:
在模拟计算过程中,发现直接处理正多边形,难度较大,通过正多边形的外接圆,进行处理,就容易许多,
下面以正方形为例
下面以正八边形为例
提交遭遇了Compilation error:
Can't compile file:
program.cpp: In function 'int main()':
program.cpp:10:7: error: 'M_PI' was not declared in this scope
a=2*M_PI/n;
^~~~
CodeForces编译环境中,竟然没有圆周率。
接下来一顿好找。笔者编译环境Ubuntu
找到圆周率后,自个在代码中,加入了宏定义。
代码结合上述正方形,正八边形分析过程,应能看懂,AC代码如下
#include <stdio.h>
#include <math.h>
#define M_PI 3.14159265358979323846
int main(){
int t,n;
double r,a,b,ans;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
n*=2;
a=2*M_PI/n;//正多边形,每条边对应的圆心角
r=1.0/2/sin(a/2);
b=(n-2)/2*a;//粉色三角形中对应的圆心角
ans=2*r*sin(b/2);
printf("%.9lf\n",ans);
}
return 0;
}