Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BOJ 18110. [Silver4] solved.ac #164

Open
hojongs opened this issue Jun 10, 2023 · 0 comments
Open

BOJ 18110. [Silver4] solved.ac #164

hojongs opened this issue Jun 10, 2023 · 0 comments

Comments

@hojongs
Copy link
Owner

hojongs commented Jun 10, 2023

Problem link

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

Problem abstraction

문제의 핵심을 요약한다. 체계적인 문제 접근을 위해, 문제를 추상화한다

적합한 자료구조를 생각한다

Design(Plan) algorithm

# 1

---
# 2

---
# 3

Algorithm idea

추상화한 문제 이해를 기반으로 알고리즘의 대략적인 구현 계획을 서술한다

Pseudo-code

idea를 수도 코드로 작성해본다

Validate algorithm

알고리즘의 유효 여부를 구현 전에 검증한다

예제 입력을 수도 코드로 계산해보고, 놓친 알고리즘 오류가 있는지 확인한다

boundary는 꼭 테스트하자

  • n=0
  • 난이도 1
  • 난이도 30

Impl

import sys

readl = sys.stdin.readline


def f():
    n = int(readl())
    if n == 0:
        print(0)
        return

    # 1~30 배열을 0으로 초기화 (난이도별 개수)
    # 난이도 입력을 받아 1~30 배열에 +1
    cnts = [0] * 31
    for _ in range(n):
        cnts[int(readl())] += 1
    # 제외할 인원 수를 구한다 (n 15% & 반올림)
    k = int(n * 0.15 + 0.5)
    # 인원 제외
    exclusion = k
    i = 1
    while exclusion > 0:
        if cnts[i] >= exclusion:
            cnts[i] -= exclusion
            break

        exclusion -= cnts[i]
        cnts[i] = 0
        i += 1

    exclusion = k
    i = 30
    while exclusion > 0:
        if cnts[i] >= exclusion:
            cnts[i] -= exclusion
            break

        exclusion -= cnts[i]
        cnts[i] = 0
        i -= 1
    # 평균을 구함 (반올림)
    print(k, cnts)
    summ = 0
    for i in range(1, 31):
        summ += i * cnts[i]
    print(int(summ / (n - k * 2) + 0.5))


f()

Self-feedback

구조적 접근: 문제를 추상화하여 구조적으로 접근했는가?

사고력: 알고리즘을 완전히 이해했는가? (충분한 사고력을 가졌는가?)

구현력: 알고리즘을 신속, 정확하게 구현했는가?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant