코딩테스트/백준

    [실1] 15724 - 주지수

    #include #include using namespace std; #define SIZE 1050 int n, m, t, arr[SIZE][SIZE]{ 0 }; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> m; for (int i = 1; i a; arr[i][j] = a + arr[i - 1][j] + arr[i][j - 1] - arr[i - 1][j - 1]; } } cin >> t; while (t--) { int x1, x2, y1, y2; cin >> x1 >> y1 >> x2 >> y2; cout

    [실4] 1120 - 문자열

    #include #include #include using namespace std; int main() { string a, b; cin >> a >> b; int aLength = a.size(), bLength = b.size(); int res = INT_MAX; for (int i = 0; i

    [실4] 3986 - 좋은 단어

    #include #include #include using namespace std; int main() { int n, res = 0; cin >> n; while(n--) { string str; cin >> str; stack s; for (int i = 0; i < str.size(); i++) { if(!s.empty() && s.top()==str[i]) { s.pop(); continue; } s.push(str[i]); } if (s.empty()) res++; } cout

    [실2] 11725 - 트리의 부모 찾기

    #include #include #include #include using namespace std; #define MAX_SIZE 100001 vector graph[MAX_SIZE]; int arr[MAX_SIZE]; bool vis[MAX_SIZE]; int main() { int n; cin >> n; for (int i = 1; i > y >> x; graph[y].push_back(x); graph[x].push_back(y); } stack s; s.push(1); vis[1] = true; while (!s.empty()) { auto idx = s.top(); s.pop(); for (int i = 0; i < graph[idx].size(..

    [실3] 15654 - N과 M (5)

    #include #include #include using namespace std; #define MAX 9 vector v; int arr[MAX]{ 0 }; bool vis[MAX]{ 0 }; int n, m; void dfs(int idx) { if (idx == m) { for (int i = 0; i m; v.resize(n); for (int i = 0; i > v[i]; sort(v.begin(), v.end()); dfs(0); }

    [골4] 1922 - 네트워크 연결

    #include #include #include using namespace std; #define MAX 100001 struct sEdge { int val, a, b; }; vector graph; int parent[MAX]; int res = 0; int Find(int x) { return (parent[x] == x) ? x : parent[x] = Find(parent[x]); } void Union(int x, int y) { x = Find(x), y = Find(y); if (x != y) parent[y] = x; } bool Cmp(sEdge edge1, sEdge edge2) { return (edge1.val < edge2.val); } int main() { ios_base:..

    [골5] 2493 - 탑

    #include #include #define y first #define x second using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL), cout.tie(NULL); int n; cin >> n; stack s; for (int i = 1; i > h; while (!s.empty()) { if (s.top().x > h) { cout

    [골4] 15683 - 감시

    https://github.com/encrypted-def/BOJ/blob/master/15683.cpp 아래는 내 코드다 cctv가 1일 때에 대비해서 풀지 못했다. #include #include #include using namespace std; using IntPair = pair; #define MAX_SIZE 100 #define y first #define x second int map[MAX_SIZE][MAX_SIZE]{ 0 }; int tmpMap[MAX_SIZE][MAX_SIZE]{ 0 }; int h, w; // CCTV 위치 저장용도 vector vC; // 다음 위치 시계 방향 IntPair pos[] { { 1, 0 }, // 북 { 0, 1 }, // 서 {-1, 0 }, /..

    [골5] 9663 - N-Queen

    #include using namespace std; int n, answer = 0; int vis[15]{ 0 }; // 유망한지 체크 bool Check(int cnt) { for (int i = 0; i < cnt; i++) { auto vis1 = vis[cnt], vis2 = vis[i]; if (vis1 == vis2 || cnt - i == abs(vis1 - vis2)) return 0; } return 1; } void BackTracking(int cnt) { if (cnt == n) { answer++; return; } for (int i = 0; i < n; i++) { vis[cnt] = i; if (Check(cnt)) BackTracking(cnt + 1); } } int ..

    [골5] 14503 - 로봇 청소기

    수정된 코드 #include #define MAX 51 #define y first #define x second using namespace std; struct Robot { int y, x, d; Robot() = default; Robot(int y, int x, int d = 0) : y(y), x(x), d(d) { } } robot; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL), cout.tie(NULL); int h, w; cin >> h >> w; cin >> robot.y >> robot.x >> robot.d; auto& y = robot.y, & x = robot.x, & d = robot.d; if (d == 1) d..