※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※

 

이번에 볼 문제는 백준 25084번 문제인 Infinity Area이다.
문제는 아래 링크를 확인하자.

https://www.acmicpc.net/problem/25084 

 

25084번: Infinity Area

For each test case, output one line containing Case #x: y, where $x$ is the test case number (starting from 1) and $y$ is the sum of areas of all the circles drawn until radius of the circle to be drawn becomes zero. $y$ will be considered correct if it is

www.acmicpc.net

반지름이 R인 원을 그리고, R*A인 원을 그린 뒤 (R*A/B)를 새로운 R로 하여 R이 양의 정수일 동안 반복하는 문제이다.

 

반복문을 이용해 위 내용을 구현하는 것으로 문제를 해결할 수 있다.

 

원주율의 근삿값은 cmath 헤더의 acos을 이용해 짧은 코드로 구해낼 수 있다.

 

아래는 제출한 소스코드이다.

#include <iostream>
#include <cmath>
using namespace std;
typedef long long ll;
typedef long double ld;

ld PI = acos(-1);

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	cout << fixed;
	cout.precision(10);

	int T; cin >> T;
	for (int t = 1; t <= T; t++) {
		ld ans = 0;
		ll R, A, B; cin >> R >> A >> B;
		while (R) {
			ans += PI * R * R;
			R *= A;
			ans += PI * R * R;
			R /= B;
		}

		cout << "Case #" << t << ": " << ans << '\n';
	}
}
728x90

+ Recent posts