본문 바로가기

알고리즘

(401)
8658 static void solution(void) { int number; int max = 0, min = 0x7FFFFFFF; for (int i = 0; i max) max = s; if (s < min) min = s; } printf("%d %d\n", max, min); } 10진수 값에서 각 자리수만 추출하여 더하면 되는 간단한 문제이다.
5650 static int N; static int board[100][100]; static int map_y[11][100]; static int map_x[11][100]; static int d[4][2] = { -1, 0, //up, 0 1, 0, //down, 1 0, -1, //left, 2 0, 1 //right, 3 }; static int changed[4][6] = { 1, 1, 3, 2, 1, 1, 0, 3, 0, 0, 2, 0, 3, 0, 1, 3, 3, 3, 2, 2, 2, 1, 0, 2 }; static bool out_of_bound(int y, int x) { if (y = N) return true; if (x = N) return true; ..
1949 static int N, K; static int board[8][8]; static int start[5][2]; //최고봉 위치는 최대 5개, static int d[4][2] = { -1, 0, //up 1, 0, //down 0, -1, //left 0, 1 //right }; static int visit[8][8]; static int max_len; static inline bool out_of_bound(int y, int x) { if (y = N) return true; if (x = N) return true; return false; } static void __solution(int y, int x, int len, int is_cut) { if..
8568 static int N; static int permu[1000]; static int solution(void) { int tmp, ret = 0; list cache[3][3]; //해당 위치에서 필요한 나머지, 실제 나머지, 값의 위치 scanf("%d", &N); for (int i = 1; i
8567 static int table[100000 + 1]; static int ans[100000 + 1]; static int N; static void table_init() { for (int i = 1; i
2117 static int N, M; static int board[20][20]; static int d[2][2] = { -1, 0, //up 1, 0 //down }; typedef struct { int y, x, len; }info; static bool out_of_bound(int y, int x) { if (y = N) return true; if (x = N) return true; return false; } static int get_home(int k, int y, int x) { int ret = 0, len = 2 * k - 1; queue q; q.push({ y, x, len }); //중심, len -= 2; for (int i = 1; i < ..
5653 static int N, M, K; static int board[1024][1024]; static int state[1024][1024]; static int org[1024][1024]; static int tmp[1024][1024]; static int d[4][2] = { -1, 0, //up 1, 0, //down 0, -1, //left 0, 1 //right }; static int solution(void) { queue q; queue qq; scanf("%d %d %d", &N, &M, &K); for (int y = 512 - N, cnt1 = 0; cnt1 < N; y++, cnt1++) { for (int x = 512 - N, cnt2 = 0; cnt2 < M; x++, cn..
8557 static double p; static long long N; static double solution(void) { scanf("%lf %lld", &p, &N); double ret = p, priv = p; if (p == 1.0) return (double)(N % 2); else if (p == 0.0) return 0.0; else if (N >= 5462564) return 0.5; for (int i = 2; i = 1 이다. 그리고 g(n) = 1 - f(n) 이므로, f(n) = p + (1 - 2p) * f(n - 1) 이 된다. 그리고 입력으로 주어지는 p는 0 이상 1이하이다. 그래서 p = 0, p = 1 에 대해 계산을 해보면, p = 0; -> f(n) = 0 p = 1;..
8556 static char str[1024]; static void solution(void) { char * ptr = str; int a = 0, b = 1; // a / b stack s; scanf("%s\n", str); while (*ptr != 0) { s.push(*ptr); if (*ptr == 'w') ptr += 4; else ptr += 5; } if (s.top() == 'w') a = 90; else a = 0; s.pop(); for (int i = 1; s.size(); i++) { a *= 2; b *= 2; if (s.top() == 'w') a += 90; else a -= 90; s.pop(); } while (a % 2 == 0 && b % 2 == 0) { a /= 2;..
2382 typedef pair pos; static int N, M, K; static int board[2][100][100]; static int direction[2][100][100]; static int tmp[100][100]; static queue q; static int d[5][2] = { 0, 0, -1, 0, //상, 실수했던 부분, 1, 0, //하, // 0, -1, //좌 0, 1 //우 }; static int changed[5] = { 0, 2, 1, 4, 3 }; static int solution(void) { int y, x, nr, dir; int turn = 0, ret = 0; scanf("%d %d %d", &N, &M, &K); for (int i = 0; i < K..