전체 글

내가 구현한 코드 (실패)function solution(n) { let q = []; let arr = []; arr[0] = 0; q.push(0); while(q.length > 0){ let cur = q.shift(); if(cur == n){ return arr[cur]; } if(arr[cur * 2] === undefined){ arr[cur * 2] = arr[cur]; q.push(cur * 2); } if(arr[cur + 1] === undefined){ arr[..
function solution(A,B){ var answer = 0; A.sort((a, b) => a-b); B.sort((a, b) => b-a); for(i = 0; i A는 최솟값부터, B는 최댓값부터 원소를 곱해서 answer에 더함
package cote;import java.util.Arrays;import java.util.Scanner;public class swea_2001_파리퇴치 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int T = sc.nextInt(); for(int i = 0; i 입력받은 N*N크기의 배열을 하나씩 탐색하면서 max값 갱신하는 방식
import java.util.*;public class Solution { public static void main(String[] args) { Scanner sc = new Scanner(System.in); for(int i = 0; i 입력받은 상자들의 높이를 정렬최댓값에 -1, 최솟값에 +1 후 정렬을 덤프 횟수만큼 반복최댓값-최솟값 출력
import java.util.LinkedList;import java.util.Queue;import java.util.Scanner;public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int K = sc.nextInt(); int arr[] = new int[100001]; Queue q = new LinkedList(); q.offer(N); while(!q.isEmpty()) { int cur = q.poll(); if(cur == K) { System.out.println(arr[cur]); br..
import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int T = sc.nextInt(); for(int i = 0; i mid = N / 2를 계산하여 중간 위치를 찾음j에 따라 start와 end를 설정해 다이아몬드 범위를 결정start부터 end-1까지의 숫자를 합산하여 value에 더함
그래프정점 : 그래프 노드 또는 점간선 : 정점 간의 연결, 부모-자식 개념 없음가중치 : 간선(엣지)에 할당된 값차수 : 정점에 연결된 간선의 수진입 차수 : 방향 그래프에서 특정 정점으로 들어오는 간선의 수진출 차수 : 방향 그래프에서 특정 정점에서 나가는 간선의 수경로 :두 정점 간에 존재하는 간선의 연속사이클 : 시작 정점에서 출발하여 다시 시작 정점으로 돌아오는 경로. 트리와 가장 큰 차이연결 그래프 : 모든 정점이 서로 연결된 그래프포화 그래프 : v개의 정점을 가지는 그래프는 최대 V * (V-1) / 2 간선이 가능부분 그래프 : 원래 그래프의 일부 정점과 간선으로 구성된 그래프방향 그래프 : 간선에 방향이 있는 그래프무방향 그래프 : 간선에 방향이 없는 그래프 DFS최대한 깊이 들어간 후..
package graph;import java.util.Scanner;public class Main { static int[] dr = { 0, 1, 0, -1 }; static int[] dc = { 1, 0, -1, 0 }; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int T = sc.nextInt(); for (int t = 1; t = N || r + dr[dir] = N || c + dc[dir] n을 입력받고 n*n크기의 배열 생성0, 0에서부터 인덱스를 채워나가면서 배열의 크기를 벗어나거나, 이미 숫자가 입력되어 있으면 방향 전환
import java.util.Scanner;public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n = sc.nextInt(); System.out.println("어느 한 컴퓨터공학과 학생이 유명한 교수님을 찾아가 물었다."); print(n, 0); } public static void print(int n, int count) { String under = "____".repeat(count); System.out.println(under+"\"재귀함수가 뭔가요?\""); if(n==0) { System.out.println(under+"\"재귀함수는 자기 ..
import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.util.StringTokenizer;public class Main { static int x, y, H, W; static char[][] map; static char direction; public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int T = Integer.parseInt(br.readLine());..