일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
- 호반우 상인
- LIS #가장긴증가하는부분수열 #
- BOJ
- 백준 #다익스트라 #dijkstra #9370 #c++
- 백준
- 쌤쌤쌤
- 줄어드는수
- 18870
- 논문리뷰 #3DReconstruction
- C++
- 최소 #공배수 #최대 #공약수 #유클리드 #호제법 #lcm #gcd #c++ #boj #3343 #백준 #장미
- 투포인터 #백준 #boj #20922 #22862
- 진법변환 #2to10 #10to2 #이진법 #십진법 #변환 #bitset #c++
- 16202
- graph #최단경로
- c++ #boj #
- backtracking #codetree #디버깅 #삼성코테
- 레드아보
- 코딩
- 서울앵무새
- 1174
- 20117
- c++ #입출력 #속도 #ios #sync_with_stdio #cin #cout #tie
- 22869
- 이분탐색 #dp #11053
- N번째큰수
- boj #백준
- 좌표압축
- 3D #Reconstruction #computer #vision #volume #metric #tsdf #kinect #fusion
- 3343
- Today
- Total
목록알고리즘 연습 (102)
hyunjin
문제 1차 코드 #include #include #include #include #include #define MAX_H 30 #define MAX_N 10 using namespace std; int N, H; bool grid[MAX_H+1][MAX_N+1]; vector candi; int ans = 10; bool InRange(int x) { return 0 ans) return; if (Verify()) ans = min(ans, cnt); if (cnt > 3) return; for (int i = start; i < candi.size(); i++) { int y, x; tie(y, x) = candi[i]; //선 겹침 if (InRange(x - 1) && grid[y][x - 1]) ..
15663 set 풀이 set은 키의 중복 허용하지 않고 키값 정렬시킨다. //참고 사이트 https://tooo1.tistory.com/327 #include #include #include #include #define MAX 9 using namespace std; int N,M; int num[MAX]; //input bool visited[MAX]={0,}; int arr[MAX]; set s; void Backtrack(int depth){//depth : depth이자 arr의 index if(depth == M){ vector v; for(auto i = 0; i>N>>M; for(int i = 0 ; i>num[i]; sort(num,num+N); Backtrack(0);//depth 의..
백준 이중 우선순위 큐 문제를 읽고 priority_queue 오름차순, 내림차순 2개를 사용해서 풀었으나 고려해야할 부분이 더 생겼고 결국 틀렸다. priority_queue 처럼 자동으로 정렬되면서 대신 앞 뒤 두 방향으로 다 접근 가능한 container가 set이라는 것을 찾았다. 그런데 set은 중복이 허용되지 않고 중복이 허용되는 것은 multiset이었다. 헤더파일 : #include multiset 사용법 multiset은 기본으로 오름차순 정렬된다. [소스 코드] multiset 사용 // multiset 사용법 #include #include #include using namespace std; typedef long long ll; void Solve(){ int testCase; c..
문제 바로가기 pow를 직접 구현하는 문제이다. 가장 단순하게 for문 돌려서 구현하면 당연히 시간 초과가 나온다. 연산 횟수를 줄여야한다. 예를 들어 $A^{4} = (A^{2})^2 $ : 짝수일때 $A^{5} = A * (A^{2})^2 $ : 홀수일때 이렇게 연산을 줄일 수 있다. 원래대로라면 $A^{4} $는 A*A*A*A로 연산이 총 3번이지만 2번으로 줄일 수 있게 된다. 즉, log2N 으로 연산 횟수가 줄어든다. 이것을 pow함수로 구현해주면 된다. #include using namespace std; typedef long long ll; ll A,B,C; void Input(){ cin >> A>>B>>C; } ll pow(int b){ if(b==0) return 1; ll tmp ..
BOJ 2170 선긋기 [실패 소스코드] 배열을 만들어 해당 구간 방문시 TRUE TREU인 곳에만 길이 구하기 #include using namespace std; typedef long long ll; int main(){ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); ll len = 2000000010, bias = 1000000000; //2000000010 1000000000 bool line[len]={0,}; int n; ll answer=0; cin >> n; for(int i=0;i>s>>e; for(ll j = s ; j>s>>e; v.push_back({s,e}); } sort(v.begin(),v.end()); int s = v[0].first..
BOJ 줄어드는 수 문제 풀이 1. 가장 큰 줄어드는 수는 9876543210 이다. 10자리. 2. 기장 큰 수를 알고 있으므로 먼저 9876543210까지의 줄어드는 수를 모두 구한다. 3. 그 다음 정렬 후 n 번째 수를 출력, 범위 넘어가면 -1 출력 소스 코드 #include using namespace std; typedef long long ll; void MakeIncreNum(ll num, int level, vector& v){ if(level > 10) return; v.push_back(num); for(int i = num%10-1 ; i>=0 ;i--){ MakeIncreNum(num*10 + i, level+1, v); } } int main(){ ios::sync_with_s..
BOJ 도서관 골드5 정렬 문제 풀이 좀 버벅거리면서 풀었다. 중요 포인트는 양수 음수 따로 생각해줘야한다는 것. m개 묶음에서 가장 먼 곳의 거리*2해서 더하고 마지막으로 간 곳에서 원점으로 되돌아올 필요없으니 빼준다. 소스 코드 #include using namespace std; int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,m,p_pos=0; cin >> n >> m; int dis[n]; for(int i = 0 ; i >dis[i]; if(dis[i]= p_pos ;i-=m){ result += (dis[i]*2); } for(int i = 0; i< p_pos ;i+=m){ result +=..
BOJ 20117 문제 자체가 어렵지 않다. gold 5 [힌트] 가장 비싸게 팔 수 있는 방법은 가장 비싼 것과 싼 것을 묶어라. [문제 풀이] 짝수 묶음의 경우 (a, b) (a>n; int qual[n]; for(int i = 0 ; i >qual[i++]; sort(qual,qual+n); int max_profit = 0; for(int i = n-1 ; i >= (int)((n+1)/2) ; i-- ){ max_profit += qual[i]; } max_profit = (n%2==0) ? max_profit*2 : max_profit*2 + qual[n/2]; cout