(C++) - 백준(BOJ) 1629번 : 곱셈 답
https://www.acmicpc.net/problem/1629 1629번: 곱셈 첫째 줄에 A, B, C가 빈 칸을 사이에 두고 순서대로 주어진다. A, B, C는 모두 2,147,483,647 이하의 자연수이다. www.acmicpc.net 풀이방법 a^b%c를 구하는 문제다. a를 b번 곱하게 되면 O(b)의 시간이 거리게 되지만 a ^ b/2 * a ^ b/2 로 곱하게 된다면 시간은 O(2 * logN)의 시간이 걸린다. 따라서 이 문제는 분할 정복 문제라고 볼 수 있다. Code #include using namespace std; long long a, b, c; long long cal(long long a, long long b, long long c) { if (b == 0) { re..
(C++) - 백준(BOJ) 7562번 : 나이트의 이동 답
https://www.acmicpc.net/problem/7562 간단한 BFS문제였습니다. 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657#include #include using namespace std; int a[301][301], c[301][301], d[301][301];int cnt, t, u, uf, v, vf, I;int dx[] = { -1,-2,-2,-1,1,2,2,1 }, dy[] = { -2,-1,1,2,2,1,-1,-2 }; void BFS(int i, int j){ queue q; q.push(make_pair(i, j)); c[i][j..
(C++) - 백준(BOJ) 2583번 : 영역 구하기
#include #include #include #include using namespace std; queue q; vector dcnt(101); int la,ra,lb,rb, m, n, k, a[101][101],c[101][101], dx[] = { 0,0,-1,1 }, dy[] = { -1,1,0,0 },cnt; void BFS(int i,int j,int cnt) { q.push(make_pair(i,j)); dcnt[cnt]++; c[i][j] = 1; while (!q.empty()) { int x = q.front().first; int y = q.front().second; q.pop(); for (int i = 0; i < 4; i++)//4방향을 살펴본다 { int nx = x + ..
C++(씨쁠쁠)(cplusplus)-백준(baekjoon)(BaekJoon)코딩 13700번:완전범죄 답
123456789101112131415161718192021222324252627282930313233343536373839404142434445#include #include using namespace std;int N, S, D, F, B, K, cnt[100001], nb, nf, police[100001], p, c[100001];queue q;void BFS(int x){ q.push(x); while (!q.empty()) { x = q.front(); q.pop(); int nb = x - B; int nf = x + F; if (0 N >> S >> D >> F >> B >> K; for (int i = 1; i > p; police[p] = 1; } cnt[D] = -1; BFS(S);..