반응형
    
    
    
  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
구현 문제였습니다.
📕 풀이방법
📔 입력 및 초기화
1. n, 현재위치 cur, gear가 도는 방향 curDir을 선언해줍니다. 연결 정보를 위한 vector graph를 struct Conn을 담도록 선언해줍니다. 2. 연결정보를 for loop로 graph에 입력 후 저장해줍니다.
📔 풀이과정
목적지에 도착할 때까지 while loop을 돌면서
다음 gear의 번호를 cur에 저장해줍니다.
연결정보의 type이 반시계방향이라면 curDir을 바꿔줍니다.
📔 정답출력
curDir를 출력해줍니다.
📕 Code
#include <bits/stdc++.h>
using namespace std;
int n, cur, curDir;
struct Conn{ int dest, type; };
vector <Conn> graph[1001];
int main(){
    cin >> n;
    for(int i = 0; i < n - 1; i++){
        int u, v, t;
        cin >> u >> v >> t;
        if(u == 1) cur = u, curDir = t;
        graph[u].push_back({v,t});
    }
    while(1) {
        cur = graph[cur][0].dest;
        if(cur == n) break;
        if(graph[cur][0].type) curDir = 1 - curDir;
    }
    
    cout << curDir;
}'Algorithm > Implementation' 카테고리의 다른 글
| (C++) - 백준(BOJ) 6162 : Superlatives (1) | 2021.12.21 | 
|---|---|
| (C++) - 백준(BOJ) 6138 : Speed Reading (0) | 2021.12.20 | 
| (C++) - 백준(BOJ) 5751 : Head or Tail (0) | 2021.12.18 | 
| (C++) - 백준(BOJ) 5692 : 팩토리얼 진법 (0) | 2021.12.17 | 
| (C++) - 백준(BOJ) 5607 : 問題 1 (0) | 2021.12.16 |