본문 바로가기

알고리즘

(401)
5656 static int N, M; static char board[750][750]; static int visit[750][750][2]; static queue q; //0: left down, //1: right down, //0: y, 1: x static int dd[2][2] = { 1, -1, 1, 1 }; static bool cant_go(int y, int x) { if (y = N) return true; if (x = M) return true; if (board[y][x] == '0') return true; return false; } static int get_len(int y, int x, int dir) { if (cant_go(y, x)) ..
7830 static int N, M; static char board[750][750]; static int visit[750][750][2]; static queue q; //0: left down, //1: right down, //0: y, 1: x static int dd[2][2] = { 1, -1, 1, 1 }; static bool cant_go(int y, int x) { if (y = N) return true; if (x = M) return true; if (board[y][x] == '0') return true; return false; } static int get_len(int y, int x, int dir) { if (cant_go(y, x)) ..
8383 static char N[100000 + 1 + 1]; static int x, y, len; static char ans[100000 + 1 + 1]; static void only_one(void) { int v = N[0] - '0'; if (v >= y) ans[0] = y + '0'; else if (v >= x) //x = y) ans[i] = y + '0'; else if (v >= x) ans[i] = x + '0'; else { for (i -= 1; i >= 0; i--) { if (ans[i] == y + '0') { ans[i] = x + '0'; break; } } if (i < 0) ans[++i] = '0'; } } diff = N[i] - ans[i]; } if (i < le..
7793 static char board[50][50]; static char visit[50][50]; static int N, M; static int ny[4] = { 1, -1, 0, 0 }; static int nx[4] = { 0, 0, 1, -1 }; static queue q[2]; //0: player, 1: devil static int __solution(void) { int depth = 1; while (!q[0].empty()) { int q_size = q[1].size(); //악마를 먼저 확산 for (int i = 0; i < q_size; i++) { pair cur = q[1].front(); q[1].pop(); for (int cnt = 0; cnt < 4; cnt++) {..
8382 static int src[2]; //y, x static int dst[2]; //y, x static int solution(void) { scanf("%d %d %d %d", &src[1], &src[0], &dst[1], &dst[0]); int dy = src[0] dx ? dy : dx; int diff = max - min; if (diff % 2) return max * ..
5658 static int N, K; static int muls[] = { 0x1, 0x10, 0x100, 0x1000, 0x10000, 0x100000, 0x1000000 }; static int translator[255]; static long long ans[28]; static void init_translator(void) { char values[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; int v = 0; for (int i = 0; i < sizeof(values) / sizeof(char); i++) translator[values[i]] = v++; } static int cm..
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[..