전체 글

Hello World
· 백준
코드#include using namespace std;int n, a[130][130], white, blue;// 길이만큼 전부 체크// 만약에 해당 부분이 색종이로 채워지지 않으면// 4등분해서 확인 (좌상 우상 좌하 우하)bool check(int x, int y, int len, int num) { for(int i = 0; i > n; for(int i = 0; i > a[i][j]; } } go(0, 0, n); cout 풀이종이는 모두 2^x의 길이를 가지고 있다. 주어지는 n도 2,4,8,16,32,64,128 중 하나이며 분할정복으로 쉽게 해결할 수 있다. go 함수를 처음 실행하면 전체 길이를 검사한다. 만약 종이 크기가 맞다면 색종이 개수를 증가시키고 종료한다. 그게 아니라면 길이..
· 백준
코드#include #include #include using namespace std;typedef long long ll;ll n,dp[11][1003],res;// dp테이블은 [마지막 숫자][숫자의 길이]를 의미ll go(int len, string s) { if(len == n) return 1; // 목표 길이에 도달했으므로 1 반환 ll &ret = dp[s[len - 1] - '0'][len]; if(ret != 0) return ret; // i가 마지막 숫자보다 크거나 같은 경우 for(int i = 0; i = s[len - 1] - '0') { ret += go(len + 1, s + to_string(i)) % 10007; } } return ret % 10007;}int m..
· 백준
코드#include #include #include #include using namespace std;int n;int timetable[10003], indegree[10003], result[10003];vector adj[10003];int main() { cin >> n; // 입력 처리 for (int i = 1; i > time >> count; timetable[i] = time; // 작업에 걸리는 시간 저장 for (int j = 0; j > pre_task; adj[pre_task].push_back(i); // 선행 작업 관계 설정 indegree[i]++; // 해당 작업의 선행 작업 개수 증가..
· 백준
코드#include #include #include #include #include #include using namespace std;struct edge { int x, y, cnt;};const int dx[] = { 0, 0, 1, -1 };const int dy[] = { 1, -1, 0, 0 };int n, res, visited[53][53];string s;char a[53][53];int bfs() { deque dq; dq.push_back({ 0, 0, 0 }); visited[0][0] = 1; while (!dq.empty()) { int px = dq.front().x; int py = dq.front().y; int cnt = dq.front().cnt; if (px =..
· 백준
코드#include #include #include #include using namespace std;int m, n, x, y, z, lst[200003], cnt, res, total;vector>> adj;int find(int x) { if (x == lst[x]) return x; return lst[x] = find(lst[x]);}void merge(int x, int y) { x = find(x); y = find(y); if (x > y) lst[x] = y; else lst[y] = x;}bool cmp(pair> a, pair> b) { return a.first > m >> n; if (m == 0 && n == 0) break; CLEAR(); for (int i = 0; ..
· 백준
코드#include #include #include #include using namespace std;int n, m, lst[1003], u, v, d, cnt, res;char uv[1003]; // 대학교 성별 저장vector>> adj; // 길 저장// 유니온 파인드 for 크루스칼int find(int x) { if (x == lst[x]) return x; return lst[x] = find(lst[x]);}void merge(int x, int y) { x = find(x); y = find(y); if (x > y) lst[x] = y; else lst[y] = x;}// 비용 순 정렬bool cmp(pair> a, pair> b) { return a.first > n >> m; fo..
· 백준
코드#include #include #include #include using namespace std;int n;string s;// 유클리드 호제법, 최대공약수 구하기int gcd(int x, int y) { while (y) { int tmp = x; x = y; y = tmp % y; } return x;}// 문자열 파싱vector split(string s, string sp) { vector v; long long idx = -1; while ((idx = s.find(sp)) != string::npos) { string tmp = s.substr(0, idx); v.push_back(tmp); s.erase(0, idx + sp.length()); } v.push_back(s)..
· 백준
코드#include #include using namespace std;stack st; // 오큰수를 찾을 스택stack answer; // 정답을 넣어줄 스택int n, a[1000003];void FASTIO() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);}int main() { FASTIO(); cin >> n; for (int i = 0; i > a[i]; for (int i = n - 1; i > -1; i--) { // top을 검사하면서 top보다 작은 경우를 탐색 while (st.size()) { int top = st.top(); if (top > a[i]) break; st.pop()..
· 백준
코드1#include #include #include #include using namespace std;// 아기 상어의 크기는 2// 0은 빈칸, 1,2,3,4,5,6은 물고기의 크기 9는 상어// 먹을 수 있는 물고기가 1마리라면 그 물고기를 먹음// 먹을 수 있는 물고기가 여러 마리라면 가장 가까이에 있는 물고기 먹음// 거리가 가까운 물고기가 많다면 가장 위에 있는 물고기, 그런 게 많다면 가장 왼쪽에 있는 물고기를 먹음 (> 사용)// 이동 시 1초, 물고기를 먹으면 빈 칸// 아기상어는 자신의 크기와 같은 수의 물고기를 먹으면 크기 1 증가// 자신의 크기보다 큰 물고기 칸 통행 X, 나머지칸 지나감// 먹는 것은 자기보다 작은 물고기만// 거리는 bfs로 찾자const int dx[] = ..
· 백준
코드#include #include #include #include #include using namespace std;typedef long long ll;struct st { int fm, fs, fd;};const int dx[] = {-1, -1, 0, 1, 1, 1, 0, -1};const int dy[] = {0, 1, 1, 1, 0, -1, -1, -1};int n, M, k, r, c, m, s, d, res;vector a[52][52];vector b[52][52];void go() { // 이동 for (int i = 0; i 1) { int nm = 0, ns = 0; bool isodd = true, iseve..