일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- 표준 입출력
- 매크로
- 장고란
- correlation coefficient
- string 메소드
- Django란
- 자료구조
- EOF
- double ended queue
- c++
- 연결요소
- Django Nodejs 차이점
- 프레임워크와 라이브러리의 차이
- 입출력 패턴
- 입/출력
- 구조체와 클래스의 공통점 및 차이점
- k-eta
- 알고리즘 공부방법
- vscode
- scanf
- 2557
- 이분그래프
- UI한글변경
- getline
- 엑셀
- 백준
- 시간복잡도
- iOS14
- string 함수
- Django의 편의성
- Today
- Total
목록알고리즘/백준풀이7. 수학 (17)
Storage Gonie
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/cj56Hy/btqu6L602v8/LRK78mMgYndC7wV8injjX0/img.png)
문제 풀이 자세한 풀이 : # C++ - 인수분해한 결과에서 2의 개수를 구할때, 바로 이전 문제에서 5의 개수를 구할 때 사용한 방법을 똑같이 사용하면 된다. - 단, i*=2, i*=5의 결과가 int형을 넘을 수 있으므로 long long 형을 사용한다. #include #include using namespace std; int main() { int n, m; // 1 > m; // nCm = n! / m!(n-m)! int two = 0; for (long long i = 2; i
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/dsxDeI/btqu55LDPYb/rwaeAvIRmPsKKKEdkLOKHk/img.png)
문제 풀이 자세한 풀이 : # C++(나의 풀이) - 팩토리얼을 펼쳤을 때 각각의 수를 소인수분해 해서 5의 개수를 셈 - 이것보다는 백준 풀이가 훨씬 간단하다. #include #include #include using namespace std; int main() { int n; cin >> n; vector vec; for (int i = 1; i
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/cG9tGE/btqu621IGQE/tHKCpN1kZYL7iNlxH8tLZK/img.png)
문제 풀이 자세한 풀이 : # C++ #include using namespace std; int factorial(int n) { if (n > n; cout
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/chIQ3S/btqu7oXLJBI/X1bgPOgb44L5xrVC5fjwEk/img.png)
문제 풀이 자세한 풀이 : # C++ #include using namespace std; int main() { int n; cin >> n; for (int i = 2; i*i
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/bHB5iy/btqu2b7gW1M/jyPNmdbQhbFvXixc8kwpM1/img.png)
문제 풀이 자세한 풀이 : # C++ #include #include using namespace std; const int MAX = 1000000; // 6
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/lgeqM/btqu1BkIV7p/j4xn0ZPc2ZwjbtXO0lVXU1/img.png)
문제 풀이 자세한 풀이 : # C++(나의 풀이) - endl을 썼다가 시간초과가 났으므로 "\n"을 사용하자. - i*i 대신 i*2로 해준 방식으로 중복적인 연산이 존재하기 때문에 아래의 방식보다 불리하기 때문에 4ms정도 더 소요되지만 크게 문제될 정도의 시간이 아니기 때문에 소수를 수집하여 컨트롤하기 좋은 이 방식을 선호하여 사용하는 것이 좋다. #include #include using namespace std; int main() { int m, n; // 1 > n; vector check(n+1); // 초기값은 defualt로 false임 vector prime_vec; check[0] = true; check[1] = true; for (int i = 2; i = m) prime_vec..
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/ekO0su/btqu2GZV1VU/K1fraV1krd8UostNMkoAbK/img.png)
문제 풀이 자세한 풀이 : # C++ => O(N루트N) - N = 100, 'N루트N' = 1000으로 1억에 못미치는 값이므로 문제없다. #include #include #include using namespace std; bool is_prime(int n) { bool flag = true; if (n n; vector vec(n); for (int i = 0; i > vec[i]; int count = 0; for (int i = 0; i < n; i++) { if(is_prime(vec[i])) count ++; } cout O(N^2) - N = 100, 'N^2' = 10000으로 1억에 못..
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/caALc5/btqu2G6gduS/nqKqWIWwruX4QhcLkuwGR1/img.png)
문제 풀이 자세한 풀이 : # C++ - 10진수 -> B진수 변환하는 부분을 string으로 처리했었는데, 벡터 방식으로 바꾼 이유는 2자리 수의 경우 reverse를 해주면 앞뒤가 바껴버리기 때문에 문제가 발생할 수 있기 때문이다. 그러므로 벡터 방식으로 처리하자. #include #include #include #include using namespace std; int main(){ int A, B; int count; int nums[30]; // 입력받는 부분 cin >> A >> B; cin >> count; for (int i = 0; i > nums[i]; // A진수 -> 10진수 변환하는 부분 int ans = 0; for (int i = 0; i <..
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/liZ0N/btqu2GLWSMt/7SlBRONB8kNCUKYWkzHrJ0/img.png)
문제 풀이 자세한 풀이 : # C++(나의 풀이) - 백준의 재귀방식을 풀어씀 #include #include #include using namespace std; int main(){ int n; cin >> n; string s; while(n != 0) { if (n%2 == 0) { s += "0"; n = -(n/2); } else { if(n > 0) n = -(n/2); else n = (-n+1)/2; s += "1"; } } reverse(s.begin(), s.end()); if (s.size() == 0) cout
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/9fnMm/btqu2UpAumj/C286kSPfgTnGDx4QMokXG1/img.png)
문제 풀이 자세한 풀이 : # C++(나의 풀이) - 각 자리를 2진수로 변환해주는 것은 공통적으로 이뤄지는 것이므로 함수화 하였고, 두번째 자리부터는 함수의 결과에다가 앞에 0을 채워주었음. #include #include #include using namespace std; string change8to2(char c) { string result = ""; int num = c - '0'; if(num == 0) // 이걸 해주지 않으면 0이 입력일 때 빈 문자열이 반환된다. return "0"; while (num != 0) { result += to_string(num % 2); num = num / 2; } reverse(result.begin(), result.end()); return re..