公式
A - π 解説
by
A - π 解説
by
sounansya
AtCoder をはじめたばかりで何をしたらよいか分からない方は、まずは practice contest の問題 A「Welcome to AtCoder」を解いてみてください。基本的な入出力の方法が載っています。
また、プログラミングコンテストの問題に慣れていない方は、AtCoder Beginners Selection の問題をいくつか解いてみることをおすすめします。
円の面積は半径 \(r\) と円周率 \(\pi\) を用いて \(\pi r^2\) と表すことができます。
半径は直径の半分なので \(\displaystyle r=\frac d2\) が成り立ちます。したがって、求める面積は \(\displaystyle \frac{\pi d^2}4\) と表せます。
あとはこの値を計算して出力すれば良いです。円周率は例えば Python であれば math ライブラリの中に pi が、C++ であれば cmath ライブラリの中に M_PI があるので、この定数を使えば良いです。
from math import pi
d = int(input())
print(d * d * pi / 4)
#include <bits/stdc++.h>
using namespace std;
int main() {
int d;
cin >> d;
cout << fixed << setprecision(20) << M_PI * d * d / 4 << endl;
return 0;
}
投稿日時:
最終更新:
