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

 

이번에 볼 문제는 백준 6060번 문제인 Wheel Rotation이다.
문제는 아래 링크를 확인하자.

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

 

6060번: Wheel Rotation

Farmer John has an old-time thresher (wheat harvester) that requires belts to be installed on various gears to turn the parts. The engine drives pulley 1 in a clockwise direction which attaches via a belt to pulley 2. Pulley 2 attaches via a belt to pulley

www.acmicpc.net

바퀴가 회전하는 방향은 다른 변수에 상관없이 벨트를 straight로 걸었는지 crossed로 걸었는지의 여부에 의해서만 결정된다. 구체적으로 벨트를 straight로 걸면 그 벨트가 연결하는 두 바퀴의 회전 방향은 동일하고, crossed로 걸면 그 벨트가 연결하는 두 바퀴의 회전방향은 서로 반대방향이다.

 

따라서 이 문제는 벨트를 crossed하게 건 횟수가 홀수번인지 짝수번인지의 여부를 살피는 것으로 해결할 수 있다.

 

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

#include <iostream>
using namespace std;

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

	int ans = 0;
	int N; cin >> N;
	N--;
	while (N--) {
		int x; cin >> x >> x >> x;
		ans ^= x;
	}

	cout << ans;
}
728x90

'BOJ' 카테고리의 다른 글

[BOJ 14915 // C++] 진수 변환기  (0) 2022.09.29
[BOJ 1233 // C++] 주사위  (0) 2022.09.28
[BOJ 6059 // C++] Pasture Walking  (1) 2022.09.26
[BOJ 18003 // C++] Checkerboard  (0) 2022.09.25
[BOJ 1368 // C++] 물대기  (1) 2022.09.24

+ Recent posts