Recent Posts
Recent Comments
Archives
Today
Total
05-21 00:42
관리 메뉴

이것저것 잡동사니

[백준 문제] 1709번: 타일 위의 원 본문

컴퓨터공학/백준 문제

[백준 문제] 1709번: 타일 위의 원

Park Siyoung 2021. 8. 8. 22:55
반응형

문제 바로가기 : https://www.acmicpc.net/problem/1709

 

설명은 나중에 시간 나면 적는걸로...


소스코드

#include <iostream>

using namespace std;

#define CHK_TILE(x, y, R) ((x * x + y * y < R * R) && ((x + 1) * (x + 1) + (y + 1) * (y + 1) > R * R))

int main(void) {
	long long N;
	cin >> N;

	long long R = N / 2;

	long long cnt = 0;
	long long x = 0, y = R - 1;

	long long move[3][2] = { {1, 0}, {0, -1}, {1, -1} };
	while (x != y) {
		cnt++;
		for (int i = 0; i < 3; i++) {
			long long nx = x + move[i][0];
			long long ny = y + move[i][1];

			if (CHK_TILE(nx, ny, R)) {
				x = nx, y = ny;
				break;
			}
		}
	}

	cout << 4 + cnt * 8;

	return 0;
}
반응형
Comments