Algorithm(218)
-
[BOJ] 1629번 : 곱셈
1. problem : https://www.acmicpc.net/problem/1629 2. solution 1 :#include using namespace std;long long recursion(long long base,long long exp, long long mod) { if (exp == 1) return 1; long long half = recursion(base, exp / 2, mod) % mod; long long result = (half * half) % mod; if (exp % 2 != 0) result = (base * result) % mod; return result;}int main(void) { ios::sync_with_stdio(0); cin.tie(0); ..
2024.08.15 -
[BOJ] 5427번 : 불
1. problem : https://www.acmicpc.net/problem/5427 2. solution 1 :#include using namespace std;#define X first#define Y second // board 생성string board[1002];// fire dist 생성int dist_f[1002][1002];// 상근 dist 생성 int dist_s[1002][1002]; // queue 생성 queue> Qf;queue> Qs;// dx,dy 생성 int dx[4] = { 1,0,-1,0 };int dy[4] = { 0,1,0,-1 };int T, row, col; int main(void) { ios::sync_with_stdio(0); cin.tie(0); c..
2024.08.14 -
[BOJ] 7562번 : 나이트의 이동
1. problem :https://www.acmicpc.net/problem/7562 2. solution 1 : #include using namespace std;#define X first#define Y second int dx[8] = { 2,2,-2,-2,1,1,-1,-1 };int dy[8] = { 1,-1,1,-1,2,-2,2,-2 }; int T; // testcase 값; int row, col;int dist[302][302];pair initpos;pair finalpos;queue> Q;int main(void) { cin >> T; while (T--) { int is_arrive = false; cin >> row; col = row; cin >> initpos..
2024.08.14 -
[BOJ] 7569번 : 토마토
1. problem :https://www.acmicpc.net/problem/7569 2. solution 1 :#include using namespace std; #define X first#define Y second #define Z third int board[102][102][102];int days[102][102][102]; int col, row, height; int dx[6] = { 1,0,-1,0,0,0 };int dy[6] = { 0,1,0,-1,0,0 };int dz[6] = { 0,0,0,0,1,-1 }; bool found = false; queue> Q; // x,y,z를 담기위해 tuple을 이용; int main(void) { ios::sync_with_stdio(0)..
2024.08.14 -
[BOJ] 10026번 : 적록색약
1. problem : https://www.acmicpc.net/problem/10026 2. solution 1 :#include using namespace std;#define X first#define Y second string board[102];int vis[102][102]; int row,col; // row == col;int dx[4] = { 1,0,-1,0 };int dy[4] = { 0,1,0,-1 };int normal_count;int color_count;queue> Q;void bfs(int x, int y,char color) { Q.push({ x,y }); vis[x][y] = 1; while (!Q.empty()) { pair cur = Q.front(); Q..
2024.08.13 -
[BOJ] 1012번 : 유기농 배추
1. problem :https://www.acmicpc.net/problem/1012 2. solution 1 :#include using namespace std; #define X first #define Y second int board[52][52]; int vis[52][52]; int dx[4] = { 1,0,-1,0 };int dy[4] = { 0,1,0,-1 };int T, row, col, K; // test case 수, 세로, 가로, 배추 갯수; int main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> T; while (T--) { memset(board, 0, sizeof(board)); // 배열 초기화 memset(vi..
2024.08.13