문제링크 : https://www.acmicpc.net/problem/2057#include using namespace std;typedef long long ll;ll arr[20];int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll N; cin >> N; if(N==0) { cout =0; i--) { if(N>=arr[i]) N-=arr[i]; } cout 먼저 가능한 팩토리얼을 모두 계산해준다.N이 10의 18제곱까지 이기에, 19!까지 계산할 필요가 있다. (19! -> 121,645,100,408,832,000 [약 1.2* 10^17]) 이후에는 ..
문제링크 : https://www.acmicpc.net/problem/17269#include using namespace std;typedef long long ll;int arr[26] = {3, 2, 1, 2, 4, 3, 1, 3, 1, 1, 3, 1, 3, 2, 1, 2, 2, 2, 1, 2, 1, 1, 1, 2, 2, 1};vectorv;string result;void cal(vectorv){ if(v.size()==2) { result = to_string(10*v[0]+v[1])+'%'; return; } vectortmp; for(int i=0; i> N >> M >> s1 >> s2; int len = max(N, M); f..
문제링크 : https://www.acmicpc.net/problem/5671#include using namespace std;typedef long long ll;int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N, M; while(cin >> N >> M) { int cnt = 0; for(int i=N; im; for(int j=0; j 1) flag = 1; } if(!flag) cnt++; } cout 입력받은 N~M까지 중복된 숫자를 체크해준다.해당 값을 문자열로 바꾼 후, 각 값을 map..
문제링크 : https://www.acmicpc.net/problem/16208#include using namespace std;typedef long long ll;int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll N, sum = 0; cin >> N; vectorv(N); for(int i=0; i> v[i]; sum += v[i]; } ll result = 0; for(int i=0; i 최소의 비용으로 쇠막대를 자른 다고 하였지만, 사실 어떻게 자르든 총 비용은 같다.따라서 정렬할 필요없이 v[i] 값과 v[i]를 제외한 나머지 값을 곱한 값을 누적해가며 총 비용을 구해주면..
문제링크 : https://www.acmicpc.net/problem/1418#include using namespace std;int arr[100001];int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N, K; cin >> N >> K; for(int i=2; i 입력받은 N을 토대로, 2~N까지 값에 대해 소인수 값을 체크해준다.해당 j 및 j의 배수에 대해 현재 소인수 i를 모두 넣어준다.이를 반복하며, ~N까지 모든 소인수를 갱신하며 소인수 중 최대값을 저장하게 된다. 이후에 해당 값들을 다시 순회하며 K보다 크지 않은 경우에 카운팅후 출력하면 된다.
문제링크 : https://www.acmicpc.net/problem/15719#include using namespace std;int arr[10000001];int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; while(N--) { int n; cin >> n; if(arr[n]) { cout 중복된 값을 체크하는 것이기에 이미 입력받은 값에 대해 처리된 경우가 있다면 바로 해당 n을 출력하고 종료한다.n의 값이 크기 때문에 map으로 할 경우 시간초과가 발생한다. (10000000 * log(10000000))
문제링크 : https://www.acmicpc.net/problem/2725#include using namespace std;bool check[1001][1001];int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int C, N; cin >> C; check[1][1]=1; for(int i=1; i> N; int result = 2; //(0, 1) (1, 0)은 항상 보이는 점 for(int i=1; i 원점과 좌표의 최대 공약수가 1이라면 겹치는 좌표가 없다는 뜻이다. 따라서 이를 통해 보이는 점의 개수 카운팅이 가능하다.먼저 전체 범위에 대해 미리 gcd 계산을 통해 가능한 값..
문제링크 : https://www.acmicpc.net/problem/1564#include using namespace std;int main() { ios::sync_with_stdio(false); cin.tie(nullptr); long long N, result=1; cin >> N; for(int i=1; i 백준 2553번 마지막 팩토리얼 수와 유사한 문제이다.뒤에 출력하는 자릿수만 다른 형태이다. 값이 더 크기에 모듈러 연산하는 값도 확장해준다.그리고 출력할 때는 5자리에 맞춰 100000로 모듈러한 값을 출력한다.이때 주의할 것은 맨 앞이 0인 경우 생략되어 나온다.따라서 이를 0으로 채워주어야 한다. C++에서는 setw(5)로 5자리 맞추고, settill(..
문제 링크 : https://www.acmicpc.net/problem/2553#include using namespace std;int main() { ios::sync_with_stdio(false); cin.tie(nullptr); long long N, result=1; cin >> N; for(int i=1; i 입력받은 N에 대해 팩토리얼 계산을 하되, 0은 모두 지워준다.그리고 해당 값이 엄청나게 커지기 때문에, 적절한 값으로 모듈러 연산을 해주어야 한다.너무 작은 값이나 너무 큰 값으로 모듈러 연산을 하면 시간초과가 발생한다. 이후 자리 수를 출력해야 하기 때문에 계산된 result에 10을 모듈러 연산하여 출력해주면 된다.
문제링크 : https://www.acmicpc.net/problem/20186#include using namespace std;int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N, K; cin >> N >> K; vectorv; for(int i=0; i> n; v.push_back(n); } sort(v.rbegin(), v.rend()); int result = 0; for(int i=0; i 규칙에 따른 최대 점수를 내기 위해서는 자신의 점수와 선택된 수의 개수 차이가 가장 커야 한다.선택된 수의 개수는 0부터 시작해 하나씩 증가하기에, 이에 맞춰 점수를 내..
문제 링크 : https://www.acmicpc.net/problem/15954#include using namespace std;int arr[501];double result = INT_MAX;int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N, K; cin >> N >> K; for(int i=0; i>arr[i]; for(int i=K; i 최소 K개 이상의 연속된 위치에 있는 인형들을 선택해야 하기에, 첫 반복문 인덱스를 K부터 N까지 설정한다.그리고 K개 이상의 연속된 구간을 지정해야 하기에 추가적인 반복문으로 구간을 선택해준다. 이제 마지막 반복문에서 해당 구간에 대해서 표준 편차를 구해준다...
문제 링크 : https://www.acmicpc.net/problem/11502#include using namespace std;int arr[1001];int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; for(int i=2; i> N; bool flag = 0; for(int i=2; i 먼저 주어진 N 범위 이내의 값을 모두 소수 판별하여 배열에 체크해준다.이후 세개의 소수 및 오름차순 체크이므로 3중 반복문을 통해 각 값이 소수가 맞는지, 그리고 합이 N이 맞는 지 체크한다.이 경우 맞다면 바로 삼중 반복문의 각 인덱스들을 순서대로 출력해주면 ..
문제 링크 : https://www.acmicpc.net/problem/24039#include using namespace std;bool isPrime(int n){ if(n > N; int result = 0; int idx = 2, prev = 0; while(1) { if(isPrime(idx)) { result = prev * idx; if(result > N) break; prev = idx; } idx++; } cout 두 소수를 구하기 위해 변수 2개를 선언한다.기본 시작은 2로, 해당 변수를 계속 증가시켜가며 다음 소수를 체크한다.만약 소수..
문제 링크 : https://www.acmicpc.net/problem/2980#include using namespace std;int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N, L; cin >> N >> L; int cur = 0, prev = 0; while(N--) { int D, R, G; cin >> D >> R >> G; cur += (D-prev); int tmp = R+G; if(cur % tmp 기본적으로는 신호등 간의 거리를 계산해 누적하며 더해준다.이때 빨간불 + 초록불의 한 사이클을 파악하여, 해당 사이클 내에 ..
문제 링크 : https://www.acmicpc.net/problem/19539#include using namespace std;int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; int sum = 0; int cnt2 = 0; for (int i = 0; i > h; sum += h; cnt2 += h / 2; //다른 물뿌리개 가능 횟수 } if (sum % 3 != 0 || cnt2 기본적으로 나무 하나를 1만큼 성장시키거나, 2만큼 성장시키기에 한 번에 3만큼 성장시킨다는 것을 알 수 있다.따라서 나무 높이의 합산이 3의 배수여야만 ..