[백준][Java] 1822번 차집합
·
백준/이분 탐색
문제https://www.acmicpc.net/problem/1822 코드import java.io.*;import java.util.*;public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int[] input = Arrays.stream(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); int N = input[0]; int M = input[1]; in..
[백준][Java] 13144번 List of Unique Numbers
·
백준/투 포인터
문제https://www.acmicpc.net/problem/13144 코드import java.io.*;import java.util.*;public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int N = Integer.parseInt(br.readLine()); int[] nums = Arrays.stream(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); int ..
[백준][Python] 1205번 등수 구하기
·
백준/구현
코드def solution(): # 하지만, 같은 점수가 있을 때는 그러한 점수의 등수 중에 가장 작은 등수가 된다. ## 90, 90, 90인 3명이 존재할 경우 가장 높은 등수를 적어준다. n, taesoo, p = map(int, input().split()) if n > 0: scores = list(map(int, input().split())) else: print(1) return # 만약, 랭킹 리스트가 꽉 차있을 때, 새 점수가 이전 점수보다 더 좋을 때만 점수가 바뀐다. ## 이 말은 태수의 점수가 랭킹의 가장 낮은 점수보다 무조건 높아야한다. # 출력 등수보다 적은 참여자가 존재한다면. if n = ..
[백준][Python] 1976번 여행 가자
·
백준/분리 집합
코드def solution(): n = int(input()) m = int(input()) global parent parent = [i for i in range(n)] for i in range(n): row = list(map(int, input().split())) for j in range(n): if row[j] == 1: union(i, j) plan = list(map(int, input().split())) root = find_parent(plan[0] - 1) for i in range(m): if find_parent(plan[i] - 1) != root: print("NO") return print..
[백준][Python] 1027번 고층 건물
·
백준/구현
코드import sysdef can_see(x1, y1, x2, y2, x3, y3): giulgi = (y2 - y1) / (x2 - x1) return giulgi * (x3 - x1) + y1 > y3 def solution(): n = int(input()) count = [0 for _ in range(n)] li = list(map(int, input().split())) # n은 50보다 같거나 작은 자연수 n^2 가능할듯 for i in range(n - 1): for j in range(i + 1, n): flag = True ## 사이에 접하거나 막히는 건물이 있는지 확인 for s in range(i + 1, j): if..
[백준][Python] 202920번 영단어 암기는 어려워
·
백준/구현
코드import sysfrom collections import defaultdictinput = sys.stdin.readlinedef solution(): ## 1. 자주 나오는 언어일수록 앞에 배치 ## 2. 해당 언어의 길이가 길수록 앞에 배치 ## 3. 알파벳 사전순 answer = [] appear = defaultdict(int) n, m = map(int, input().split()) for _ in range(n): word = input().strip() if len(word) >= m: appear[word] += 1 sorted_li = sorted(appear.items(), key=lambda x: (-x[1], -len(x[0]), x[0..
[백준][Python] 23971번 ZOAC 4
·
백준/구현
코드def solution(): h, w, n, m = map(int, input().split()) row = w // (m + 1) if w % (m + 1) > 0: row += 1 col = h // (n + 1) if h % (n + 1) > 0: col += 1 print(row * col)solution() 풀이사람이 앉아야하는 좌석과 유지되어야하는 간격을 합쳐서 일렬로 최대로 나열할 수 있는 만큼 계산한다.한 행에 나열될 수 있는 사람 수를 계산한다.row = w // (m + 1)행의 마지막 사람은 오른쪽에 주어진 간격을 지킬 필요가 없으니 한 자리라도 남았다면 사람을 배치할 수 있다.if w % (m + 1) > 0: row += 1열도 이와 마찬가지로 계산..
[백준][Python] 20125번 쿠키의 신체 측정
·
백준/구현
코드# 시작 시간 12시 49분## 첫 제출 1시 22분def solution(): n = int(input()) grid = [list(input()) for _ in range(n)] # 두 번째 줄에는 각각 왼쪽 팔, 오른쪽 팔, 허리, 왼쪽 다리, 오른쪽 다리의 길이를 공백으로 구분해서 출력하여라. answer = [] center_x, center_y = 0, 0 for i in range(n - 1): for j in range(n - 1): if grid[i][j] == '*': if grid[i][j + 1] == '*' and grid[i][j - 1] == '*' and grid[i - 1][j] == '*' and grid[i + 1][j] == ..
개발자 성현
'백준' 카테고리의 글 목록