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

 

이번에 볼 문제는 백준 26340번 문제인 Fold the Paper Nicely이다.
문제는 아래 링크를 확인하자.

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

 

26340번: Fold the Paper Nicely

Dr. Orooji has a daily calendar (365 pages) on his desk. Every morning, he tears off one page and, as he is reading the notes on the next page, he folds (out of habit) the sheet in his hand. Dr. O noticed that he always folds the sheet (a rectangular paper

www.acmicpc.net

각 테스트케이스에 대하여, 종이를 접어야하는 횟수만큼 (더 긴 변의 길이를 절반(홀수의 경우 소수점버림)으로 접는 행동)을 직접 시뮬레이션해 문제를 해결하자.

 

문제의 답을 찾기 전에 "Data set: "로 시작하는 첫 행을 미리 출력해두면 추가적인 변수를 사용하지 않아도 된다.

 

답을 출력할 때 항상 긴 변을 먼저 출력해줘야 함에 유의하자.

 

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

#include <iostream>
#include <utility>
using namespace std;

int T;

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

	cin >> T;
	while (T--) {
		int x, y, n; cin >> x >> y >> n;
		cout << "Data set: " << x << ' ' << y << ' ' << n << '\n';
		if (x < y) swap(x, y);
		while (n--) {
			x >>= 1;
			if (x < y) swap(x, y);
		}

		cout << x << ' ' << y << '\n' << '\n';
	}
}
728x90

+ Recent posts