목록백준 (25)
천천히 빛나는
본 포스팅에서는 [Z, 드래곤커브, 외판원순회, 월드컵, 야구공, 빵집]을 다룹니다. 1074. (실버 1) Z import java.io.*; import java.util.*; public class Main { static int N, r, c, sz, ans; static int map[][]; static boolean success; static void makeZ(int x, int y, int size) { if (size == 1) return; if (x (size / 2) - 1) { // 오..
본 포스팅에서는 [이차원 배열과 연산, 요세푸스 문제, 안전영역, 배열돌리기3, 신기한 소수]을 다룹니다. 17140. (골드4) 이차원 배열과 연산 import java.io.*; import java.util.*; public class Main { static int r, c, k; static int map[][]; static int time; static int freq[]; static ArrayList list = new ArrayList(); static int maxRow, maxCol; static int tempMaxRow, tempmaxCol; static class Pair { int freq; int val; Pair(int freq, int val) { this.freq = ..
Day 1에서는 [연구소, 연산자 끼워넣기, 감시, 스타트와 링크, 치킨배달, 톱니바퀴, 인구이동, 퇴사]를 다룹니다. 14502. (골드4) 연구소 import java.io.*; import java.util.*; class Pair{ int first; int second; public Pair(int first, int second) { this.first = first; this.second = second; } public int first() { return first; } public int second() { return second; } } public class Main { static int N, M; static int[][] map = new int[8][8]; static fi..
본 포스팅에서는 [스타트와 링크, 마법사 상어와 블리자드, 마법사 상어와 복제, 주사위 굴리기 2]를 다룹니다. 14889. (스타트와 링크) 오늘은 스타트링크에 다니는 사람들이 모여서 축구를 해보려고 한다. 축구는 평일 오후에 하고 의무 참석도 아니다. 축구를 하기 위해 모인 사람은 총 N명이고 신기하게도 N은 짝수이다. 이제 N/2명으로 이루어진 스타트 팀과 링크 팀으로 사람들을 나눠야 한다. 축구를 재미있게 하기 위해서 스타트 팀의 능력치와 링크 팀의 능력치의 차이를 최소로 하려고 한다. #include #include using namespace std; int N; int S[21][21]; vector v; int totalSum; int minDiff = -1; void makeTeam(in..
본 포스팅에서는 [상어초등학교, 스타트택시, 마법사 상어와 파이어스톰, 마법사 상어와 비바라기]를 다룹니다. 21608. (상어 초등학교) 학생의 만족도의 총 합을 구해보자. #include #include #include #include using namespace std; int N; int classRoom[21][21]; int dx[] = { -1, 0, 0, 1 }; int dy[] = { 0, -1, 1, 0 }; struct Student { int s; int sLike[4]; }; queuestudents; Student resultRoom[21][21]; void assignSeat() { int maxLike = -1; int maxEmpty = -1; pair tempLike; p..
본 포스팅에서는 [이차원 배열과 연산 , 컨베이어 벨트 위의 로봇, 마법사 상어와 파이어볼, 마법사 상어와 토네이도]를 다룹니다. 17140. (이차원 배열과 연산) 배열 A에 들어있는 수와 r, c, k가 주어졌을 때, A[r][c]에 들어있는 값이 k가 되기 위한 최소 시간을 구해보자. #include #include #include #include using namespace std; int c, r, k; int A[101][101]; int cRnum; int cCnum; int result; void Calculation() { if (A[r][c] == k) { cout 등장횟수의 오름차순으로 정렬된다. 등장횟수가 같으면 그 다음 값인 수의 오름차순으로 정렬된다. 4) 기존 저장되어있던 값을..
본 포스팅에서는 [주사위 굴리기, 아기상어, 나무 재테크, 2048, 낚시왕]을 다룹니다. 14499. (주사위 굴리기) 주사위는 지도의 바깥으로 이동시킬 수 없다. 만약 바깥으로 이동시키려고 하는 경우에는 해당 명령을 무시해야 하며, 출력도 하면 안 된다. #include #include #include using namespace std; int n, m, x, y, k; int dx[] = { 0, 0, -1, 1 }; int dy[] = { 1, -1, 0, 0 }; int dice[7]; int map[20][20]; vectorcmd; pair now; bool change(int d) { int nx = now.first + dx[d - 1]; int ny = now.second + dy[d..
본 포스팅에서는 [시험감독, 연산자 끼워넣기, 로봇 청소기, 톱니바퀴, 미세먼지 안녕!, 감시, 뱀]을 다룹니다. 13458. (시험 감독) 각 시험장마다 응시생들을 모두 감시해야 한다. 이때, 필요한 감독관 수의 최솟값을 구하는 프로그램을 작성하시오. #include #include #include using namespace std; int n; int a; double b, c; vectorv; int main() { cin >> n; while (n--) { cin >> a; v.push_back(a); } cin >> b >> c; long long total = v.size(); for (int i = 0; i 0) total += ..
1260. (DFS와 BFS) 그래프를 DFS로 탐색한 결과와 BFS로 탐색한 결과를 출력하는 프로그램을 작성하시오. 단, 방문할 수 있는 정점이 여러 개인 경우에는 정점 번호가 작은 것을 먼저 방문하고, 더 이상 방문할 수 있는 점이 없는 경우 종료한다. 정점 번호는 1번부터 N번까지이다. #include #include #include #include using namespace std; vectorgraph[1001]; int n, m, v; bool visited1[1001]; bool visited2[1001]; void dfs(int x) { visited1[x] = 1; cout m >> v; for (int i = 0; i > x >> y; ..
2609. (최대공약수와 최소공배수) 두 개의 자연수를 입력받아 최대 공약수와 최소 공배수를 출력하는 프로그램을 작성하시오. #include #include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); int a, b; cin >> a >> b; int minVal = 1; int n = min(a, b); while (n > 1) { if (a % n == 0 && b % n == 0) { minVal *= n; a /= n; b /= n; n = min(a, b); } n--; } cout > b; cout > a >> b; cout n; while (n--) { cin >> x; int temp = 0; ..