본문 바로가기

알고리즘/SWEA

(95)
7673 static int N; static int board[1000][1000][4]; // 10의 개수, 2의 개수, 5의 개수, 원래 수 static int table[1000001][4]; //10의 개수, 2의 개수, 5의 개수, hit/miss static bool visit[1000][1000]; static queue q; static int d[2][2] = { 0, 1, //right 1, 0 //down }; static void translation(int n) { int cp = n; int divs[] = { 10, 2, 5 }; if (table[cp][3] || cp == 0) return; for (int i = 0; i < 3; i++) { int cnt = 0; while (..
6855 static int N, K; static int house[100000]; static int between[100000]; static int cmp(const void * p1, const void * p2) { int n1 = *(int *)p1; int n2 = *(int *)p2; return n1 - n2; } static int solution(void) { int ret = 0; scanf("%d %d", &N, &K); scanf("%d", &house[0]); for (int i = 1; i = N) return 0; if (K =..
7730 static int N, M; static int trees[1000000]; static int cmp(const void * p1, const void * p2) { int n1 = *(int *)p1; int n2 = *(int *)p2; return n2 - n1; } static int solution(void) { int H, ret = 0; scanf("%d %d", &N, &M); for (int i = 0; i < N; i++) scanf("%d", &trees[i]); qsort(trees, N, sizeof(int), cmp); int max = trees[0], min = 0; while (min H; i++) sum += (trees[i] - H); if (sum < M) max ..
1953 static int N, M; static char board[2000][2000]; static char ans[4096]; static int visit[2000][2000]; static queue q[2]; static void solution(void) { int len = 0, y = 0, x = 0, turn = 0; scanf("%d %d", &N, &M); for (int i = 0; i < N; i++) scanf("%s\n", board[i]); ans[len++] = board[0][0]; q[turn].push(pair(0, 0)); while (len < N + M - 2) { char min = 0x7f; if (q[turn].size() == 1) { pair cur = q[..
7396 static int N, M; static char board[2000][2000]; static char ans[4096]; static int visit[2000][2000]; static queue q[2]; static void solution(void) { int len = 0, y = 0, x = 0, turn = 0; scanf("%d %d", &N, &M); for (int i = 0; i < N; i++) scanf("%s\n", board[i]); ans[len++] = board[0][0]; q[turn].push(pair(0, 0)); while (len < N + M - 2) { char min = 0x7f; if (q[turn].size() == 1) { pair cur = q[..
6719 static int N, K; static int course[200]; static int cmp(const void * p1, const void * p2) { int n1 = *(int *)p1; int n2 = *(int *)p2; return n2 - n1; } static double solution(void) { double ret = 0; scanf("%d %d", &N, &K); for (int i = 0; i = 0; i--) { ret += course[i]; ret /= 2; } return ret; } 문제의 해결책..
7812 static int N, M; static int ground[10000]; static queue q; static int solution(void) { int tot = 0, ret = 0; scanf("%d %d", &N, &M); for (int i = 0; i M) { tot -= q.front(); q.pop(); } if (tot == M) { ret += 1; tot -= q.front(); q.pop(); } } while (!q.empty()) q.pop(); return ret; } 과거에 풀었던 문제 중에..
1952 static int price[4]; //1day, 1month, 3months, 1year static int month[12]; static int __solution_(int m, int value) { if (m >= 12) { return value; } else { int sel; if (month[m] * price[0] < price[1]) sel = month[m] * price[0]; else sel = price[1]; int r1 = __solution_(m + 1, value + sel); int r2 = __solution_(m + 3, value + price[2]); return r1 < r2 ? r1 : r2; } } static int __solution(int tot_d..
6959 static char numbers[1024]; static char winner[] = { 'A', 'B' }; static char solution(void) { int digit, turn = 1; scanf("%s\n", numbers); digit = numbers[0] - '0'; for (int i = 1; numbers[i] != 0; i++) { digit += (numbers[i] - '0'); if (digit >= 10) //두 자리 { int q = digit / 10, r = digit % 10; digit = q + r; turn = 1 - turn; } turn = 1 - turn; } return winner[turn]; } 1234라는 숫자가 있고, 여기서 인접한 두 수의..
4088 static int N, maximum, minimum; static int ops[4]; //0: +, 1: -, 2: *, 3: / static int numbers[12]; static int sel[11]; static void __solution(int idx, int st) { if (idx == 4) { int v = numbers[0]; for (int i = 0, j = 1; i < N - 1; i++, j++) { switch (sel[i]) { case 0: v += numbers[j]; break; case 1: v -= numbers[j]; break; case 2: v *= numbers[j]; break; case 3: v /= numbers[j]; break; } } if (..