백준 1057번

2022. 3. 7. 03:22·Study/Algorithm

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

 

1057번: 토너먼트

김지민은 N명이 참가하는 스타 토너먼트에 진출했다. 토너먼트는 다음과 같이 진행된다. 일단 N명의 참가자는 번호가 1번부터 N번까지 배정받는다. 그러고 난 후에 서로 인접한 번호끼리 스타를

www.acmicpc.net

#include <iostream>
#include <vector>

using namespace std;

int main() {
	//std::ios::sync_with_stdio(false); std::cin.tie(NULL); std::cout.tie(NULL);


	int N, kim, im;
	cin >> N >> kim >> im;

	int play[100001];
	memset(play, 0, 100001 * sizeof(int));
	play[kim] = 1;
	play[im] = 1;
	bool end = false;
	int round = 1;

	while (true) {
		for (int i = 1; i <= N; i += 2) {
			if (play[i] == 1 && play[i + 1] == 1) {
				end = true;
				break;
			}
			if (play[i] == 1 || play[i + 1] == 1) {
				play[i] = 0;
				play[i + 1] = 0;
				play[(i + 1) / 2] = 1;
			}
		}
		if (end)
			break;
		round++;

	}
	cout << round;
}

'Study > Algorithm' 카테고리의 다른 글

백준 13140번  (0) 2022.03.27
백준 17135번  (0) 2022.03.14
백준 2428번  (0) 2022.02.28
백준 10025번  (0) 2022.02.28
백준 1940번  (0) 2022.02.28
'Study/Algorithm' 카테고리의 다른 글
  • 백준 13140번
  • 백준 17135번
  • 백준 2428번
  • 백준 10025번
_WooHyun_
_WooHyun_
  • _WooHyun_
    Nerd
    _WooHyun_
  • 전체
    오늘
    어제
    • 분류 전체보기 (79)
      • Study (60)
        • Algorithm (24)
        • Unreal Engine (19)
        • C++ (1)
        • Maya (1)
        • GoLang (3)
        • Mysql (3)
        • Linux (7)
        • Server (2)
      • Projects (0)
        • Unreal Engine (0)
        • Server (0)
      • 개발일지 (8)
        • Unreal Engine (7)
        • Art (1)
        • Server (0)
      • 미래 (5)
      • 개발아이디어 (0)
      • 잡지식 (2)
  • 블로그 메뉴

    • 홈
    • 방명록
    • 글쓰기
    • 블로그설정
  • 링크

    • GitHub
  • 공지사항

  • 인기 글

  • 태그

  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
_WooHyun_
백준 1057번
상단으로

티스토리툴바