목록Java (52)
rose_brown

1. 문제https://www.acmicpc.net/problem/10816 2. 코드python 1import sysinput = sys.stdin.readlinen=int(input())N=sorted(map(int,input().split()))m=int(input())M=map(int,input().split())def binary(l,N,start,end): if start>end: return 0 m = (start+end)//2 count=0 if l==N[m]: return N[start:end+1].count(l) elif l풀이이분탐색을 위해 리스트 N 정렬중간값이랑 비교n ! = 중간요소인 경우 → 탐색범위를 절반으로..
1. 문제https://school.programmers.co.kr/learn/courses/30/lessons/67257 2. 코드python 1from itertools import permutationsimport redef cal(tokens): num1, exp, num2 = tokens if exp == "*": return int(num1) * int(num2) elif exp == "+": return int(num1) + int(num2) else: return int(num1) - int(num2) def solution(expression): operators = ["*","+","-"] answer =..
1. 문제https://school.programmers.co.kr/learn/courses/30/lessons/64064 2. 코드python 1from itertools import permutationsimport redef solution(user_id, banned_id): banned = ' '.join(banned_id).replace('*','.') answer = set() for i in permutations(user_id, len(banned_id)): if re.fullmatch(banned, ' '.join(i)): answer.add(' '.join(sorted(i))) return len(answer)풀이banned_id에..
1. 문제https://school.programmers.co.kr/learn/courses/30/lessons/77485 2. 코드python 1def rotate(x1, y1, x2, y2, matrix): first = matrix[x1][y1] min_value = first # 왼쪽 for k in range(x1, x2): matrix[k][y1] = matrix[k + 1][y1] min_value = min(min_value, matrix[k + 1][y1]) # 아래 for k in range(y1, y2): matrix[x2][k] = matrix[x2][k+1] min_value = min..
1. 문제https://school.programmers.co.kr/learn/courses/30/lessons/87377 2. 풀이풀이주어진 직선에서 교점을 구한다그중 정수 교점만 따로 변수로 저장한다교점을 모두 표현할 수 있는 최소한의 사각형을 구한다모든 교점을 * 로 찍어서 표현배열을 거꾸로 뒤집어 반환좌표에서는 중심이 [0,0]이지만 배열에서는 시작점이 [0,0] 이기때문 python 1def solution(line): pos, answer = [], [] n = len(line) x_min = y_min = int(1e15) x_max = y_max = -int(1e15) for i in range(n): a, b, e = line[i] fo..

1. 문제https://www.acmicpc.net/problem/2166 2. 코드pythonimport sysN = int(input())x = []y = []answer = 0for i in range(N): inputX, inputY = map(int, input().split()) x.append(inputX) y.append(inputY)x.append(x[0])y.append(y[0])for i in range(N): answer += (x[i]*y[i+1]) - (x[i+1] * y[i])print(round(abs(answer/2), 1))풀이N - 점의 개수, x - x 좌표 저장, y - y 좌표 저장for i → 0~N-1x, y 좌표 저장리스트 마지막에 처음 ..

1. 문제https://www.acmicpc.net/problem/2162 2. 코드pythonimport sysinput = sys.stdin.readlineN = int(input())parent = [-1] * (3001)def CCW(x1, y1, x2, y2, x3, y3): temp = (x1*y2 + x2*y3 + x3*y1) - (x2*y1 + x3*y2 + x1*y3) if temp > 0: return 1 elif temp 풀이N - 선분 개수, parent - 선분들의 부모 선분 저장 노드find 함수if parent[a]가 음수 → return aparent[a] = find(parent[a])return parent[a]union(a, b) 함수p = ..

1. 문제https://www.acmicpc.net/problem/17387 2. 코드pythonimport sysinput = sys.stdin.readlinex1, y1, x2, y2 = map(int, input().split())x3, y3, x4, y4 = map(int, input().split())def CCW(x1, y1, x2, y2, x3, y3): temp = (x1*y2 + x2*y3 + x3*y1) - (x2*y1 + x3*y2 + x1*y3) if temp > 0: return 1 elif temp 풀이(x1, y1) ~ (x4, y4) 입력CCW함수CCW 수행 → (x1y2 + x2y3 + x3y1) - (x2y1 + x3y2 + x1y3)retur..

1. 문제https://www.acmicpc.net/problem/11758 2. 코드pythonimport sysinput = sys.stdin.readlineA = []for i in range(3): x, y = map(int, input().split()) A.append((x,y))result = (A[0][0] * A[1][1] + A[1][0] * A[2][1] + A[2][0] * A[0][1]) - (A[1][0] * A[0][1] + A[2][0] * A[1][1] + A[0][0] * A[2][1])if result Javaimport java.io.*;import java.util.*;public class Main { public static void main(S..

1. 문제https://www.acmicpc.net/problem/14003 2. 코드pythonimport sysinput = sys.stdin.readlineN = int(input())A = list(map(int, input().split()))A.insert(0, 0)index = 0maxLength = 1B = [0] * 1000001D = [0] * 1000001ans = [0] * 1000001B[maxLength] = A[1]D[1] = 1def binarySearch(l, r, now): while l 풀이N - 수열 개수, A - 수열 저장 리스트B[] - 현재 가장 유리한 증가 수열 저장 리스트ans[] - 정답 수열 저장 리스트D[] - 0~i까지 i를 포함하는 최장 증가 수..