본문 바로가기

Coding Test

(163)
백준 1774 우주신과의 교감 https://www.acmicpc.net/problem/1774 1774번: 우주신과의 교감 (1,1) (3,1) (2,3) (4,3) 이렇게 우주신들과 황선자씨의 좌표가 주어졌고 1번하고 4번이 연결되어 있다. 그렇다면 1번하고 2번을 잇는 통로를 만들고 3번하고 4번을 잇는 통로를 만들면 신들과 선자씨끼 www.acmicpc.net #include #include #include #include #define INF 987654321 using namespace std; //우주신들의 좌표 pair god[1000001]; //{dist, v} vector edge; int parent[1001]; int findParent(int k){ return parent[k] == k ? k : paren..
백준 21919 소수 최소 공배수 https://www.acmicpc.net/problem/21919 21919번: 소수 최소 공배수 수열 중에 소수는 2, 3, 5가 있다. www.acmicpc.net #include #include #include using namespace std; bool isVisit[1000001]; bool isPrime(int k) { for (int i = 2; i > n; for (int i = 0; i > temp; if (isPrime(temp)) { prime.push_back(temp); } } //소수가 없는 경우 -1 출력 if (prime.empty()) { cout
백준 17276 배열 돌리기 https://www.acmicpc.net/problem/17276 17276번: 배열 돌리기 각 테스트 케이스에 대해 회전 연산을 마친 후 배열의 상태를 출력한다. n줄에 걸쳐 각 줄에 n개의 정수를 공백으로 구분하여 출력한다. www.acmicpc.net #include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; cin >> t; for (int test = 0; test > n >> d; for (int i = 1; i map[i][j]; } } //-90도 회전은 27..
백준 11000 강의실 배정 https://www.acmicpc.net/problem/11000 11000번: 강의실 배정 첫 번째 줄에 N이 주어진다. (1 ≤ N ≤ 200,000) 이후 N개의 줄에 Si, Ti가 주어진다. (0 ≤ Si > n; for (int i = 0; i > s >> e; cls.push_back({s,..
백준 17836 공주님을 구해라! https://www.acmicpc.net/problem/17836 17836번: 공주님을 구해라! 용사는 마왕이 숨겨놓은 공주님을 구하기 위해 (N, M) 크기의 성 입구 (1,1)으로 들어왔다. 마왕은 용사가 공주를 찾지 못하도록 성의 여러 군데 마법 벽을 세워놓았다. 용사는 현재의 가지고 있는 www.acmicpc.net #include #include #define INF 987654321 using namespace std; //0: 길, 1: 벽, 2: 칼 int map[101][101]; int cost[101][101]; bool isVisit[101][101]; int ny[4] = {-1, 1, 0, 0}; int nx[4] = {0, 0, -1, 1}; int main() { ios:..
백준 15486 퇴사 2 https://www.acmicpc.net/problem/15486 15486번: 퇴사 2 첫째 줄에 N (1 ≤ N ≤ 1,500,000)이 주어진다. 둘째 줄부터 N개의 줄에 Ti와 Pi가 공백으로 구분되어서 주어지며, 1일부터 N일까지 순서대로 주어진다. (1 ≤ Ti ≤ 50, 1 ≤ Pi ≤ 1,000) www.acmicpc.net #include #include #include #define MAX_NUM 1500001 using namespace std; //dp[i]: i일에 받을 수 있는 최대 이익 int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; int ans = 0; cin >> n; vect..
백준 2448 별 찍기 (11) divide & conquer #include #define MAX_SIZE 3072 //3*pow(2, 10) using namespace std; char star[MAX_SIZE][MAX_SIZE * 2]; //가장 윗 꼭짓점의 좌표(r,c), 별의 크기 n void makeStar(int r, int c, int n) { //deg case if (n == 3) { //ㅁㅁ*ㅁㅁㅁ star[r][c] = '*'; //ㅁ*ㅁ*ㅁㅁ star[r + 1][c - 1] = '*'; star[r + 1][c + 1] = '*'; //*****ㅁ star[r + 2][c - 2] = '*'; star[r + 2][c - 1] = '*'; star[r + 2][c] = '*'; star[r + 2][c + 1..
백준 21314 민겸 수 https://www.acmicpc.net/problem/21314 #include #include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); string s; cin >> s; vector ans; //최댓값 연산 int mcnt = 0; int kcnt = 0; for (int i = 0; i < s.size(); i++) { if (s[i] == 'M') { mcnt++; } else if (s[i] == 'K') { kcnt++; } if (kcnt != 0) { ans.push_back('5'); for (int j = 0; j < mcnt; j++) { ans.push_..