[백준] 15721번 번데기 _ Python

2023. 11. 14. 14:27·Algorithms/Brute Fource

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

 

[초기 접근 방법]

T번째 '뻔' or '데기'의 위치를 구해야 한다.

1. "뻔" or "데기"의 개수(degiCnt)가 T 이상이 때까지, lst를 늘려준다.

2. 뒤에서 x = (degiCnt - T) 번째 인덱스를 %A(사람 수) 출력 → 원탁에서 몇 번째에 있는지 출력

 

[생각]

일반적인 구현 문제였다.

 

[코드]

# 풀이 시간 : 20분
# 시간복잡도 : O(T^2)
# 공간복잡도 : O(T)
# 참고 : -

A = int(input())
T = int(input())
what = int(input())

result = []

n = 0
degiCnt = 0
while True:
    n += 1 # n회차
    lst = [0, 1, 0, 1] # '뻔' '데기' '뻔' '데기'
    lst += (n + 1) * [0] + (n + 1) * [1]
    result += lst
    
    degiCnt += 2 + n + 1 # 회차 시, 뻔 or 데기 갯수
    
    if degiCnt > T:
        x = degiCnt - T + 1 # 뒤에서 x번째 what 인덱스 % A를 하면 된다.

        whatCount = 0
        for i in range(len(result)-1, -1, -1):
            if result[i] == what:
                whatCount += 1
                if whatCount == x:
                    print(i % A)
                    exit()
저작자표시 (새창열림)

'Algorithm > Brute Fource' 카테고리의 다른 글

[백준] 18111번 마인크래프트 _ Python  (0) 2024.01.16
[백준] 2422번 한윤정이 이탈리아에 가서 아이스크림을 사먹는데 _ Python  (1) 2023.11.16
[백준] 1548번 부분 삼각 수열 _ Python  (0) 2023.11.10
[백준] 22944번 죽음의 비 _ Python  (0) 2023.11.10
[백준] 12919번 A와 B 2 _ Python  (0) 2023.11.10
'Algorithms/Brute Fource' 카테고리의 다른 글
  • [백준] 18111번 마인크래프트 _ Python
  • [백준] 2422번 한윤정이 이탈리아에 가서 아이스크림을 사먹는데 _ Python
  • [백준] 1548번 부분 삼각 수열 _ Python
  • [백준] 22944번 죽음의 비 _ Python
wch_t
wch_t
  • wch_t
    끄적끄적(TIL)
    wch_t
  • 글쓰기 관리
  • 전체
    오늘
    어제
    • 분류 전체보기 (171)
      • Architecture (0)
      • Algorithm (67)
        • Math (5)
        • Simulation (1)
        • Data Structure (4)
        • DP (7)
        • Brute Fource (10)
        • Binary Search (6)
        • Greedy (2)
        • Graph (11)
        • Mst (1)
        • Shortest path (10)
        • Two Pointer (1)
        • Tsp (3)
        • Union Find (2)
        • Mitm (1)
      • CS (2)
        • 데이터베이스 (5)
        • 네트워크 (5)
      • DB (6)
      • DevOps (17)
        • AWS (9)
        • Docker (1)
        • CI-CD (5)
      • Error (1)
      • Project (0)
        • kotrip (0)
      • Spring (59)
        • 끄적끄적 (5)
        • 기본 (9)
        • MVC 1 (7)
        • MVC 2 (11)
        • ORM (8)
        • JPA 1 (7)
        • JPA 2 (5)
        • Spring Data Jpa (7)
      • Test (2)
      • TIL (6)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    apache poi
    docker
    scope
    Jenkins
    aws secrets manager
    spring-cloud-starter-bootstrap
    백준 17289 파이썬
    백준 3015 파이썬
    Sxssf
    백준 17299 파이썬
    spring-cloud-starter-aws-secrets-manager-config
    view algorithm
    response_mode
    Merge
    form_post
    애플
    TempTable
    docker: not found
  • 최근 댓글

  • hELLO· Designed By정상우.v4.10.3
wch_t
[백준] 15721번 번데기 _ Python
상단으로

티스토리툴바