본문 바로가기
  • Let's study

PS/백준56

[C++] 백준 20046번: Road Reconstruction #include #include #include #define MAX 1e9 using namespace std; int m, n; int dis[1001][1001]; int adj[1001][1001]; int dx[4] = { 1,-1,0,0 }, dy[4] = { 0,0,1,-1 }; int visit[1001][1001]; void dijkstra(int a, int b) { fill(&dis[0][0], &dis[1000][1001], MAX); priority_queue pq; if (adj[a][b] != -1) { dis[a][b] = adj[a][b]; pq.push({ -dis[a][b], {a,b} }); } while (!pq.empty()) { int c = -pq.top().f.. 2021. 9. 9.
[C++] 백준 6764번: Sounds fishy! 오타가 있는 문제입니다. 네 수가 모두 같을 때는 "Fish at Constant Depth"라고 출력해야 하고 적혀진 세 조건을 만족하지 못했을 때는 "No Fish"라고 출력해야 합니다.(No Fish에 . 을 빼야함) #include #include using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); int arr[4]; int up = 0; int down = 0; int same = 0; for (int i = 0; i > arr[i]; } for (int i = 1; i arr[i - 1]) up++; else i.. 2021. 3. 13.
[C++] 백준 10799번: 쇠막대기 ')'가 입력될 때 이전 괄호가 '('이면 현재까지 저장된 '(' 개수를 더해주고 이전 괄호가 ')'라면 1을 더해준다. #include #include #include using namespace std; stack s; int main() { string str; cin >> str; int res = 0; for (int i = 0; i < str.size(); i++) { if (str[i] == '(') { s.push(str[i]); } else { s.pop(); if (str[i - 1] == '(') { res += s.size(); } else { res ++; } } } cout 2021. 2. 4.
[C++] 백준 16206번: 롤케이크 1. 10의 배수를 먼저 크기 순서대로 정렬한 후 나머지 숫자는 뒤에 붙인다. 2. 배열을 돌면서 10보다 크고 m>0일 동안 v[i]에서 10을 빼면서 카운트를 센다. 3. v[i]가 10인 경우를 따로 카운트 해준다. #include #include #include using namespace std; vectorv; vectorv2; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m, a; cin >> n >> m; for (int i = 0; i > a; if (a % 10 == 0) v.push_back(a); else v2.push_back(a); } sort(v.begin().. 2021. 1. 23.
[C++] 백준 2110번: 공유기 설치 #include #include #include using namespace std; vectorv; int main(){ int n, c; cin >> n >> c; for (int i = 0; i > a; v.push_back(a); } sort(v.begin(), v.end()); int left = 1; int right = v[n-1]-v[0]; int result = 0; while (left = mid) { cnt++; loc = v[i]; } } if (cnt >= c) { left = mid + 1; result = mid; } else right = mid - 1; } cout 2020. 12. 30.
[C++] 백준 10870번: 피보나치 수 5 1. 배열을 선언하고 arr[0]=0, arr[1]=1을 저장 2. 2부터 시작해서 n이 될때까지 피보나치 식을 써서 값을 구하고 배열에 저장 #include using namespace std; int arr[21]; int i = 2; int fibo(int n) { while (i > n; arr[0] = 0; arr[1] = 1; fibo(n); cout 2020. 12. 27.