Python

Algorithm/PS

[BOJ/백준] 9945 - Centroid of Point Masses [python]

문제 링크 9945번: Centroid of Point Masses Input will be sets of points. Each set will be specified by the number of points n in the set followed by n lines of three numbers representing xi, yi, and mi values for i = 1 to n. All these numbers will be integers from 1 to 5000. That is, n will be from www.acmicpc.net 문제 풀이 무게 중심을 구해주기 위해 xi * m의 합을 m의 합으로 나누어주었다. 정답 코드 cnt = 1 while True : N = int(input..

Algorithm/PS

[BOJ/백준] 9924 - The Euclidean Algorithm [python]

문제 링크 9924번: The Euclidean Algorithm The famous Euclidean algorithm is found in Book VII of the Elements. The Elements was written in 300 B.C.~by the Greek mathematician Euclid. It is rumored that King Ptolemy, having looked through the Elements, hopefully asked Euclid if there were not a sho www.acmicpc.net 문제 풀이 A, B가 주어졌을 때, 특정한 계산을 통해 B가 0이 될 때 까지의 반복문 수행 횟수를 구해준다. 정답 코드 def solve(A, B, n) :..

Algorithm/PS

[BOJ/백준] 9907 - ID [python]

문제 링크 9907번: ID The National Identity Card number of the city state of Eropagnis, NICE, consists of seven digits and a letter appended behind. This letter is calculated from the digits using the Modulo Eleven method. The steps involved in the computation are as follows: www.acmicpc.net 문제 풀이 문제에 주어진대로 입력값의 각 자릿수마다 숫자를 곱해준 뒤, 그 합을 11로 나눈 나머지를 "JABCDEFHIZ"의 인덱스로 매핑한다. 정답 코드 id_map = "JABCDEFGHIZ" ..

Algorithm/PS

[BOJ/백준] 9848 - Gift [python]

문제 링크 9848번: Gift The first line contains 2 integers n and k, where n (3 ≤ n ≤ 100) is the number of days, and k (0 < k ≤ 100,000) the desired improvement (in milliseconds). Whenever Jacqueline’s timing reduces by at least k milliseconds over the previous day’s ti www.acmicpc.net 문제 풀이 첫 줄에 주어진 K를 가지고 각각의 입력값을 전 입력값과 비교했을 때 차이가 K이상일 경우의 수를 구해 출력한다. 정답 코드 n, K = map(int, input().split()) ans = 0 ..

Algorithm/PS

[BOJ/백준] 9838 - XMAX [python]

문제 링크 9838번: XMAS Your program must write a mapping from the guests to the recipients of their gifts to the standard output. The first line contains an integer indicating the recipient of the gift brought by guest 1. Similarly, the second line contains an integer indicating www.acmicpc.net 문제 풀이 입력된 값을 인덱스로, 들어온 순서를 값으로 정해준 뒤, 순서대로 출력해준다. 정답 코드 n = int(input()) lst = [0] * (n + 1) for i in range..

Algorithm/PS

[BOJ/백준] 9783 - Easy Encryption [python]

문제 링크 9783번: Easy Encryption In order to send a secret message to your friend, you invent an original method to encrypt the message. The encryption rule is quite simple. A letter is replaced with 2-digit number. Each letter has its corresponding number as the following: a = 01, b = 02 www.acmicpc.net 문제 풀이 입력값을 문제의 규칙에 따라 변환해 출력해주는 문제이다. 알파벳은 소문자 a부터 z까지 01 ~ 26으로 변환해 출력해준다. 대문자는 A ~ Z 까지 27 ~ 5..

Algorithm/PS

[BOJ/백준] 9776 - Max Volume [python]

문제 링크 9776번: Max Volume The first line of the input contains a positive integer n (1 ≤ n ≤ 100) which is the number of figures. The n following lines contain the description of each figure. In case of a cone, the line begins with letter C and followed by 2 values: r and h res www.acmicpc.net 문제 풀이 입력값은 구, 원기둥, 원뿔로 들어오게 되는데, 각각의 부피를 구해준 뒤, 가장 부피가 큰 값을 출력해준다. 정답 코드 pi = 3.14159 ans = [] for _ in r..

Algorithm/PS

[BOJ/백준] 9773 - ID Key [python]

문제 링크 9773번: ID Key บรรทัดแรกคือค่า N (1 ≤ N ≤ 100) ระบุจํานวนคน และ N บรรทัดต่อมา แต่ละบรรทัดคือเลขประจําตัวประชาชน 13 ห www.acmicpc.net 문제 풀이 이 문제는 13자리의 수가 입력되는데, 규칙 두 가지를 통해 나온 값을 더해준 뒤, 4자리로 만들어 출력해주면 된다. 각 자릿수를 모두 더해준 값 열번째 자리부터 열 세번째 자리까지 세자릿 수에 10을 곱해준 값 두 값의 합을 구해준 뒤, 값을 1000의 자리까지만 출력해준다. 만약, 값이 4자리가 되지 않을 경우, 값에 1000을 더해 출력해준다. 정답 코드 for i in range(int(input())) : id = input() ans = s..

chanwoong1
'Python' 태그의 글 목록 (2 Page)