목록알고리즘 풀이/백준 (61)
하다보니
n=int(input()) stack=[] ans=0 for i in range(n): h=int(input()) while stack!=[] and stack[-1]
#include using namespace std; int func(int n,int r,int c) { if (n == 0)return 0; int half = 1 = half)return half*half+func(n - 1, r, c - half); if (r >= half && c = half && c >= half)return half * half * 3 + func(n - 1, r - half, c - half); } int main() { int n, r, c; cin >> n >> r >> c; cout
#include using namespace std; void func(int i,int j, int n) { if (n == 1) { cout
처음에 제출한 코드 /* F층으로 이루어진 고층 건물, S는 현재 강호 위치, G는 도착지, U는 위로 U층 가는 버튼, D는 아래로 D층 가는 버튼. U와 D버튼만으로 도착지까지 이동을 한다.최소 몇 번을 눌러야 하는가? */ #include using namespace std; int vis[1000002]; int main() { int f, s, g, u, d; cin >> f >> s >> g >> u >> d; if (s == g) { cout f || dx 0)continue; Q.push(dx); vis[dx] = vis[cur]+1; } cout > f >> s >> g >> u >> d; queue q; fill(vis+1, vis + f+1, -1); q..
#include #define X first #define Y second using namespace std; int board[1002][1002]; int dist_f[1002][1002]; int dist_s[1002][1002]; int dx[4] = { 1,-1,0,0 }; int dy[4] = { 0,0,1,-1 }; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; while (n--) { queue Qf = {}; queue Qs = {}; bool flag = false; int w, h; cin >> w >> h; for (int i = 0; i < h; i++) { fill(dist_f[i], dist_f[i] +..
- c++ #include using namespace std; using li = long long; li pow(li a, li b, li c) { if (b == 1)return a % c; li val = pow(a, b / 2, c); val = val * val%c; if (b % 2 == 0)return val; return val * a%c; } int main() { ios::sync_with_stdio(0); cin.tie(0); li a, b, c; cin >> a >> b >> c; cout
#include #define X first #define Y second using namespace std; int board[102][102]; int vis[102][102]; int dx[4] = { 1,-1,0,0 }; int dy[4] = { 0,0,1,-1 }; int main() { ios::sync_with_stdio(0); cin.tie(0); int m, n, k;//m은 세로, n은 가로, k는 사각형 개수 queue Q; vector v; cin >> m >> n >> k; while (k--) { int x1, x2, y1, y2; cin >> x1 >> y1 >> x2 >> y2; for (int i = x1; i < x2; i++) { for (int j = y1; j < ..
#include #define X first #define Y second using namespace std; int dx[8] = { 2,-2,1,-1,2,-2,1,-1 }; int dy[8] = { 1,1,2,2,-1,-1,-2,-2 }; int board[302][302]; int vis[302][302]; int main() { int n;//테스트 케이스 cin >> n; while (n--) { queue Q; int l;//체스판의 한 변의 길이 cin >> l; for (int i = 0; i > a >> b;//출발지 cin >> c >> d;//도착지 Q.push({ a,b });..
#include using namespace std; int dx[6] = { 1,-1,0,0,0,0 }; int dy[6] = { 0,0,1,-1,0,0 }; int dz[6] = { 0,0,0,0,1,-1 }; int m, n, h;//m은 가로, n은 세로, h는 높이 int board[102][102][102]; int dis[102][102][102]; queue Q; int main() { cin >> m >> n >> h; for(int k=0;k> board[i][j][k]; if (board[i][j][k] == 1) Q.push({ i,j,k }); if (board[i][j][k] == 0)dis[i][j][k] = -1; } } } while (!Q.empty()) { auto cu..
#include #define X first #define Y second using namespace std; string board[102]; bool vis[102][102]; int n; int dx[4] = { 1,-1,0,0 }; int dy[4] = { 0,0,1,-1 }; void bfs(int i, int j) { queue Q; Q.push({ i,j }); vis[i][j] = 1; while (!Q.empty()) { pair cur = Q.front(); Q.pop(); for (int i = 0; i < 4; i++) { int nx = cur.X + dx[i]; int ny = cur.Y + dy[i]; if (nx=n || ny=n)continue; if (vis[nx][ny..