실험실
  • [백준] 30143. Cookie Piles - 파이썬
    2024년 08월 27일 22시 39분 16초에 업로드 된 글입니다.
    작성자: B1NK
    728x90
    • 백준 링크: 30143번: Cookie Piles
    • solved.ac 난이도: 브론즈 IV
    • 시간 제한: 2초
    • 메모리 제한: 1024MB

    문제

    The kids in my son's kindergarten made Christmas cookies with their teacher, and piled them up in columns. They then arranged the columns so that the tops of the columns, going from shortest to tallest, were in a nice straight ramp. The cookies were all of uniform size. Given that there were A cookies in the shortest pile, that the difference in height between any two adjacent piles was D cookies, and that there were N piles, can you write a program to figure out how many cookies there were in total?

    해석

    제 아들 유치원의 아이들이 선생님과 함께 크리스마스 쿠키를 만들어 기둥에 쌓아 올렸습니다. 그런 다음 가장 짧은 기둥에서 가장 높은 기둥으로 올라가는 기둥의 꼭대기가 멋진 직선 경사로가 되도록 기둥을 배열했습니다. 쿠키의 크기는 모두 일정했습니다. 가장 짧은 기둥에 A개의 쿠키가 있고, 인접한 두 기둥의 높이 차이가 D개이며, N개의 쿠키가 있다고 주어졌을 때, 총 몇 개의 쿠키가 있는지 알아내는 프로그램을 작성할 수 있습니까?

    입력

    The first line contains the number of test cases T. T lines follow, one corresponding to each test case, containing 3 integers : N, A and D.

    해석

    첫 번째 줄에는 테스트 케이스 수 T가 포함되어 있으며, 각 테스트 케이스에 해당하는 3개의 정수인 N, A, D가 포함된 T줄이 이어집니다.

    출력

    Output T lines, each line containing the required answer for the corresponding test case.

    해석

    해당 테스트 케이스에 필요한 답을 포함하는 각 줄을 출력하는 T줄을 출력합니다.

    코드

    언어: 파이썬

    def total_cookies(N, A, D):
        return N * A + D * (N * (N - 1)) // 2
    
    def main():
        import sys
        input = sys.stdin.read
        data = input().splitlines()
    
        T = int(data[0])
        results = []
    
        for i in range(1, T + 1):
            N, A, D = map(int, data[i].split())
            result = total_cookies(N, A, D)
            results.append(result)
    
        for result in results:
            print(result)
    
    if __name__ == "__main__":
        main()
    728x90
    댓글