boj
-
나무 재테크백준알고리즘 2019. 9. 10. 18:14
#include #include using namespace std; struct tree{ int x, y; int age; }; int n, m, k; int dx[] = { 0,0,1,-1,1,1,-1,-1 }; int dy[] = { 1,-1,0,0,1,-1,1,-1 }; int map[20][20];//양분! int ori[20][20]; vector tr; vector death; void spring() { vector temping[1001]; for (int i = 0; i < tr.size(); i++) { temping[tr[i].age].push_back(tr[i]); } tr.clear(); for (int i = 0; i < 1000; i++) { if (temping[i].si..
-
미네랄백준알고리즘 2019. 9. 10. 01:54
#include #include #include using namespace std; int r, c; char map[111][111]; bool dist[111][111]; int dx[4] = { -1, 1 , 0 , 0 }; int dy[4] = { 0, 0, -1, 1 }; int main() { ios::sync_with_stdio(false); cin >> r >> c; for (int i = 1; i map[i][j]; } } int n; cin >> n; bool left = true; while (n--) { int height; cin >> height; height = r - height + 1; // del if (left == true) { for (int i = 1; i = 1..
-
쇠막대기백준알고리즘 2019. 9. 8. 15:18
#include #include #include #include using namespace std; int main(void) { int nstick = 0;//총 막대기 int result = 0; string str; stack stk; cin >> str; vector lstick;//1개의 레이저가 통과하는 막대기 for (int i = 0; i < str.length(); i++) { if (str[i] == '(') stk.push(str[i]); else { if (str[i - 1] == str[i]) { stk.pop(); nstick++; } else { stk.pop(); lstick.push_back(s.size()); }//스택에 남아있는 '('수 = 레이저가 통과하는 막대기 수..
-
오큰수백준알고리즘 2019. 9. 8. 15:10
어려웠다 #include #include #include using namespace std; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; vector v(n), ans(n); for(int i=0; i> v[i]; stack stk; stk.push(1e9+7); for(int i=n-1; i>=0; i--){ while(stk.top() = 1e9) ans[i] = -1; else ans[i] = stk.top(); stk.push(v[i]); } for(auto i : ans) cout
-
단어 뒤집기백준알고리즘 2019. 9. 5. 01:45
문제를 끝까지 읽어볼 필요가있고 예제 입출력을 한번더 볼필요가있었던문제, 내가 난독증이있는지는 모르겠지만, 그냥 처음에 문자를 아예거꾸로 뒤집는줄알았다. 그게아니여서 처음에 스택을 쓰다가 큐로바꿨고 굉장히 무난하게 푼 문자열문제 #include #include #include #include #include using namespace std; int main() { int n; cin >> n; queue x; string a; getline(cin, a); for (int i = 0; i < n; i++) { getline(cin, a); //cout
-
좋은수열백준알고리즘 2019. 9. 5. 01:44
백트래킹 문제로, 어려운 문제라기보단 귀찮은 문제가아닐까 싶었고, 확신이 쉽게들지않을문제. 첫번째, 일단 재귀를통해 수열을 만드는것은 string을 통해 쉽게 가능함 두번째, 바로앞에 중복되는 값을 수열로만드는건 굉장히 쉬움 세번째, 세번째부터 문제인데, 앞서 사용되있던 문자들과 중복체크하는것 이 굉장히 귀찮다. 하나하나 다해보기엔 시간복잡도가 터져버릴것같은문제, 전략을 세워보면, 딱 반크기만큼만 잘라서 보면된다 전체적으로 다검사해봐야하는것은 맞지만, 이어붙여나가는과정에서 이미 이어붙였던 것까지 한번에 검사할필요는 없다는얘기다. 문제를 풀어서 코드로 작성해보면다음과같다. #include #include #include #include using namespace std; vector a[80]; char..
-
레이저 통신백준알고리즘 2019. 9. 1. 23:12
BFS문제, 시뮬레이션으로도 풀수있을것 같긴한데, 그냥 끝까지가서 BFS 하면되는문제 까다로운점은 이제 한 직선내에서 모든점들에 대해 BFS를 하다보면, 중복되는지점(방문한 지점)에서 더 작은 값의대한처리는 어떻게 할지 이다. #include #include #include using namespace std; int r,c; char map[100][100]; int dist[100][100]; bool visit[100][100]; int dx[] ={0,0,1,-1}; int dy[] = {1,-1,0,0}; int ans = 0; void bfs(int x, int y){ queue q; visit[x][y] = true; q.push({x,y}); while(!q.empty()){ x= q.fr..
-
물통백준알고리즘 2019. 9. 1. 01:56
물통 A,B,C의 물의 양을 각각의 NODE라고 생각했고, 그리고 물을 옮기는 행위에 대한것을 따르거나, 따르지않거나 즉 따를때 1, 따르지 않을때 0의 가중치를 가지고있어서, BFS로 충분히 풀수있으리라고 생각했다. #include #include #include #include using namespace std; int x[201][201][201]; bool d[201][201][201]; int a, b, c; struct go{ int a, b, c; go(int a, int b, int c) { this->a = a; this->b = b; this->c = c; } }; vector zp; void bfs() { queue q; q.push(go(0, 0, c)); d[0][0][c] = ..