목록Problem Solving (49)
프로그래밍 공부
https://www.acmicpc.net/problem/17829 해결 아이디어배열을 쪼개서 문제를 해결 해야하는 것을 보니 재귀적으로 접근하면 해결이 될 것 같아서 우선 재귀적으로 접근하고우리가 구해야하는 것은 값일 뿐이니 배열을 갱신 하지는 않고 값만 리턴해서 정답을 구하면 될것 같았다 재귀적 접근#include #include #include using namespace std;int solve(vector>& v, int size, int x, int y){ if(size == 2){ vector tmp; for(int i = x; i tmp; for(int i = 0; i > n; vector> v(n, vector (n)); for(in..
https://www.acmicpc.net/problem/1992 해결 아이디어재귀를 사용한 분할 정복 문제이다 size / 2로 범위를 좁혀가며 배열을 체크하여정답 배열에 값을 추가하는 방식으로 문제를 해결하였다.#include #include using namespace std;vector ans;int n;void solve(vector& grid, int size, int x, int y){ char standard = grid[x][y]; bool check = true; for(int i = x; i > n; int size = n; vector grid(n); for(int i = 0; i > grid[i]; } solve(grid, size, 0,..
https://www.acmicpc.net/problem/2606 해결 아이디어그냥 bfs나 dfs를 돌려주면 해결된다 #include #include #include using namespace std;int main(){ ios::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n; vector> graph(n + 1); vector vis(n + 1); cin >> m; for(int i = 0; i > x >> y; graph[x].push_back(y); graph[y].push_back(x); } queue q; q.push(1); vis[1] = true; ..
https://www.acmicpc.net/problem/19591 해결 아이디어문자열 처리 부분만 잘 해주고 조건에 맞게 잘 비교하면 되는 문제였다 #include #include #include #include using namespace std;int main() { ios::sync_with_stdio(0); cin.tie(0); string str; cin >> str; deque num; deque op; string number = ""; bool sign = false; // 부호 판별 변수 시작할때 음수 판별 int len = str.length(); for(int i = 0; i & num, int idx, char op) -..
https://www.acmicpc.net/problem/10815 c++ map을 알거나 Python dictionary를 안다면 쉽게 해결 할 수 있는 문제이지만 모르면 고생을 할꺼 같다 #include #include using namespace std;int main(){ ios::sync_with_stdio(0); cin.tie(0); map mp; int n, m; cin >> n; for(int i = 0; i > tmp; mp[tmp] = true; } cin >> m; for(int i = 0; i > tmp; if(mp.find(tmp) != mp.end()){ cout
https://www.acmicpc.net/problem/2589 해결 아이디어"보물은 서로 간에 최단 거리로 이동하는데 있어 가장 긴 시간이 걸리는 육지 두 곳에 나뉘어 묻혀있다." 이 부분을 읽고문제의 의도를 파악 할 수 있었다. 최단 거리에 속을 뻔 했는데 이건 말장난이고 가장 긴 시간이 걸리는 육지 두 곳에 나뉘어 묻혀있다는게 섬하나에서 끝과 끝을 이야기 한다고 볼 수 있기 때문에 각 지점 마다 bfs를 돌린후 dis 배열의 가장 큰 값을 구하면 된다고 생각했다.#include #include #include #define X first#define Y secondusing namespace std;int dy[] = {0, 0, 1, -1};int dx[] = {1, -1, 0, 0};int ..