[백준 15610] Abbey Courtyard (C#, C++) - soo:bak
작성일 :
문제 링크
설명
정사각형 마당의 넓이가 주어질 때, 마당을 둘러싸는 전선의 총 길이를 구하는 문제입니다.
접근법
정사각형의 넓이가 a이면 한 변의 길이는 a의 제곱근입니다. 둘레는 한 변의 4배이므로, 제곱근에 4를 곱하면 됩니다.
Code
C#
1
2
3
4
5
6
7
8
9
using System;
class Program {
static void Main() {
var a = double.Parse(Console.ReadLine()!);
var perim = 4 * Math.Sqrt(a);
Console.WriteLine(perim.ToString("F6"));
}
}
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
double a; cin >> a;
cout.setf(ios::fixed);
cout << setprecision(6) << 4 * sqrt(a) << "\n";
return 0;
}