일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 |
- Computer science
- DP
- 스택
- 자료구조
- 알고리즘
- 컴퓨터공학과
- cs
- 문제풀이
- 컴공과
- 정석
- OS
- Stack
- 백준
- 그래프
- vector
- 오퍼레이팅시스템
- c++
- bfs
- 구현
- Operating System
- 너비우선탐색
- 개발
- 브루트포스
- 코딩
- 오에스
- 북리뷰
- 컴공
- coding
- 정석학술정보관
- 코테
- Today
- Total
목록coding (150)
Little Jay
1~99까지의 숫자는 모두 한수 이다. 등차수열을 생각하면 원소를 더하는 경우와 빼는 경우, 공차가 0인 경우 모두 생각하자 #include #include using namespace std; int calc(int n) { int count = 0; int first, second, third; if (n n; cout
생각보다 생각을 많이 해야했던 문제이다. 코테는 항상 문제를 잘 분석하는 것에서부터 시작한다. 1. 항상 문제를 잘 읽어야 한다 문제에 낚시가 있었는데, 그것을 긴급번호로 쓰여진 것이었다. 그러니까 당연히 긴급번호가 처음으로 들어오고 그 번호를 기준으로 substr을 하면 되는줄 알고 계속 틀렸었다. 그러나 문제는 긴급번호가 기준이 아닌 모든 전화번호를 기준으로 문제를 풀어야한다 ex) 11240 48298405824 113 113134 NO 즉, 첫 번째에 상관없이 어떤 전화번호가 다른 전화번호의 전화번호가 되면 안된다는 것이다. 2. 빠른 탐색을 위해 sort를 통해서 vector를 정렬시키고, length를 비교해서 current가 next보다 길면 넘겨버렸다 접두사라는 개념을 생각하면, curre..
#include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int number, result; int x, y, z, w; int count = 0; cin >> number; result = number; while (true) { x = number / 10; y = number % 10; z = (x + y) % 10; w = (y * 10) + z; number = w; count++; if (w == result) break; } cout
#include using namespace std; int main() { long long n; long long sum = 0; long long count = 1; cin >> n; while (true) { sum += count; if (sum > n) { count--; break; } ++count; } cout
이진탐색을 활용하는 문제 생각보다 이진탐색할때 조건을 설정하는 부분이 어려웠다 #include #include #include using namespace std; long long arr[10001]; int main() { int n, sum = 0; cin >> n; for (int i = 0; i > arr[i]; sum += arr[i]; } int budget; cin >> budget; sort(arr, arr + n); long long low = 0; long long high = arr[n - 1]; if (sum
DP가 정말 어렵다 점화식을 어떻게 구현할 것인가의 문제인데, 이 부분에서 훈련이 더 필요할 것 같다. #include #include using namespace std; int house[1005][3]; int color[1005][3]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; for (int i = 0; i > house[i][0] >> house[i][1] >> house[i][2]; } color[0][0] = house[0][0]; color[0][1] = house[0][1]; color[0][2] = house[0][2]; for (int i = 1; i < n; i++)..
int형 LinkedList 데이터 타입은 바꾸거나 typedef로 지정을 해주거나 할 수 있다. 중간에 데이터를 넣는 것은 구현하지 않았다. #include #include using namespace std; class intNode { private: int dat; intNode* next; intNode(int x) { this->dat = x; this->next = NULL; } friend class intLinkedList; }; class intLinkedList { private: intNode* head; intNode* tail; public: intLinkedList() :head(NULL), tail(NULL) { } ~intLinkedList() {} void addFront..
몰랐는데 C++에 prev_permutation이라는 강력한 기능이 있었다! #include #include #include #include using namespace std; vector v; void permutation(string& s) { sort(s.begin(), s.end(), greater()); do { //cout n; for (int i = 0; i > s; permutation(s); for (int j = v.size() - 1; j >= 0; j--) { cout
팰린드롬 문제이다 이 팰린드롬 문제때문에 전공 하나 B0받은 것을 생각하면 치가 떨리는 알고리즘(?)이다. 각설하고, 에라토스테네스의 체로 소수인 숫자들을 vector에 미리 넣어놓고 vector의 숫자보다 같거나 큰 소수들을 탐색하면서 팰린드롬인지 확인해주면 된다 숫자가 커서 vector로 문제를 풀 때 메모리가 많이 소모될 줄 알았는데 다행히 6720kb밖에 소모되지 않았다. #include #include #include #include using namespace std; #define MAX 1003001 int arr[1003002]; vector v; //에라토스테네스의 체 void prime() { for (int i = 2; i = n) { check = true; string s = t..
생각보다 너무 오래 고민했던 문제 처음에는 vector 계속 sort하는 방법을 생각했지만 그러기에는 메모리 제한에 걸릴 것이다. 그래서 검색을 하다가 deque로 하는 방법이 있어서 이 방법을 채택했다. stack과 queue는 일방적으로 뒤, 앞에 있는 원소만 다룰 수 있지만, deque는 앞, 뒤의 원소를 둘 다 다룰 수 있다는 장점이 있다. 그래서 reverse했을 때 계속해서 vector로 reverse sort 해줄 필요 없이 reverse한 것을 체크해서 앞이나 뒤에서부터 원소를 출력해주면 된다. #include #include #include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie..