본문 바로가기

알고리즘

(56)
[프로그래머스] PGS - 야근 지수 https://school.programmers.co.kr/learn/courses/30/lessons/12927#qna 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr import java.util.*;class Solution { public long solution(int n, int[] works) { long answer = 0; PriorityQueue pq = new PriorityQueue(Collections.reverseOrder()); //works를 우선순위 큐에 넣자 for(int i=0;i0 && !pq.isE..
[프로그래머스] PGS - 다음 큰 숫자 https://school.programmers.co.kr/learn/courses/30/lessons/12911 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.krimport java.util.*;class Solution { //이진수 변환 후 1의 개수 counting public int count1(int num){ int cnt = 0; while(num > 1){ if(num % 2 == 1){ cnt++; num = num / 2; } els..
[백준] BOJ2178 - 미로탐색 (JAVA) https://www.acmicpc.net/problem/2178 import java.util.*;import java.io.*;class Point{ int x; int y; Point(int x, int y){ this.x = x; this.y = y; }}public class Solution{ static int n, m; //n*m 미로 static int[][] arr; //미로 배열 static boolean[][] visited; //방문체크 static int[] dx = {-1,1,0,0}; static int[] dy = {0,0,-1,1}; static void bfs(int x, int y){ ..
[PGS] 프로그래머스 - 여행경로 (JAVA) https://school.programmers.co.kr/learn/courses/30/lessons/43164 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr import java.util.*; class Solution { static int[] visited; static PriorityQueue pq; public void dfs(String cityName, String[][] tickets, String path, int node){ if(node==tickets.length){ //다 돌았다 pq.add(path); return; } for(..
[프로그래머스] PGS - 게임 맵 최단거리 https://school.programmers.co.kr/learn/courses/30/lessons/1844# 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr import java.util.*; import java.io.*; class Solution { static class Point{ int x; int y; Point(int x, int y){ this.x = x; this.y = y; } } static int[] dx = {-1,1,0,0}; static int[] dy = {0,0,-1,1}; static int[][] visited; s..
[백준] BOJ20920 - 영단어 암기는 괴로워 (JAVA) https://www.acmicpc.net/problem/20920 20920번: 영단어 암기는 괴로워 첫째 줄에는 영어 지문에 나오는 단어의 개수 $N$과 외울 단어의 길이 기준이 되는 $M$이 공백으로 구분되어 주어진다. ($1 \leq N \leq 100\,000$, $1 \leq M \leq 10$) 둘째 줄부터 $N+1$번째 줄까지 외울 단 www.acmicpc.net import java.util.*; import java.io.*; public class Solution { static HashMap words; public static void main(String args[]) throws Exception { BufferedReader br = new BufferedReader(new ..
[PGS] 프로그래머스 - 아이템줍기 (JAVA) https://school.programmers.co.kr/learn/courses/30/lessons/87694 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr import java.util.*; import java.io.*; class Solution { static boolean[][] map; static Queue queue; static boolean[][] visited; static int ans; static int sX, sY, iX, iY; static int[] dx = {-1,1,0,0}; static int[] dy = {0,0,..
[백준] BOJ2608 - 로마 숫자 (JAVA) https://www.acmicpc.net/problem/2608 2608번: 로마 숫자 첫째 줄과 둘째 줄에 하나씩 로마 숫자로 표현된 수가 주어진다. 입력된 각 수는 2000 보다 작거나 같고, 두 수의 합은 4000보다 작다. www.acmicpc.net import java.util.*; import java.io.*; public class Solution { static HashMap hash; static int getNum(String[] num){ int sum = 0; for(int i=0;i