목록Programming/Algorithms (3)
Allen's 데이터 맛집
백준 2606번 "바이러스" 문제는 네트워크 상에서 바이러스의 감염 범위를 계산하는 문제로, 그래프 탐색 알고리즘인 DFS(깊이 우선 탐색) 또는 BFS(너비 우선 탐색)를 활용하여 해결할 수 있습니다.이 글에서는 Java를 사용해 구현한 풀이를 소개하고, 문제 해결 과정과 주요 알고리즘을 설명합니다.1. 문제 개요1.1 문제 설명컴퓨터 네트워크에서 1번 컴퓨터가 바이러스에 감염되었을 때, 네트워크를 통해 감염되는 컴퓨터의 개수를 구하는 문제입니다.컴퓨터는 노드로, 네트워크 연결은 엣지로 표현할 수 있어 그래프 탐색 문제로 접근할 수 있습니다.1.2 입력 및 출력입력:첫 줄: 컴퓨터의 수 (노드의 개수).둘째 줄: 네트워크 연결 수 (엣지의 개수).이후 줄: 각 네트워크 연결 정보 (노드 간 연결).출력..

import java.util.*;//https://programmers.co.kr/learn/courses/30/lessons/42587//Programmers stack/Queue 중 프린터 문제public class Printer { public static void main(String[] args) { int[] priorities = { 1, 1, 9, 1, 1, 1 }; int location = 2; System.out.println(solution(priorities, location)); } public static int solution(int[] priorities, int location) { int answer = 0; LinkedList list = new Lin..

import java.util.ArrayList;public class IronBar { public static void main(String[] args) { System.out.println(solution("()(((()())(())()))(())")); } public static int solution(String arrangement) { //copyArray 는 arrangement 중에 ()'레이저' 를 알아 보기 쉽게 replace()를 사용하여 0으로 바꾼후 answer 초기화 String copyArray = arrangement.replace("()", "0"); //answer 는 토막난 막대기 수. int answer = 0; ArrayList copy..