문제링크 : 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/10837#include using namespace std;int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int K, C; cin >> K >> C; for(int i=0; i> M >> N; if(M==N) { cout N) //동수가 한 번 더 던지기 가능 [2점차까지 따라붙기 가능] { cout 기본적으로 영희와 동수의 점수가 동일하다면 게임 규칙상 끝까지 진행이 가능하다.이런 경우 해당 점수 또한 가능하다는 의미이기에 바로 1을 출력한다. 이제 체크해야 할 ..
문제 링크 : 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의 배수여야만 ..
문제 링크 : https://www.acmicpc.net/problem/15965#include using namespace std;const int MOD = 1000000007;int main() { int K; cin >> K; vector isPrime(7500000, true); isPrime[0] = isPrime[1] = false; int cnt = 0; for (int i = 2; i 소수를 미리 구하면서 소수 개수를 카운팅하고, 이때 K번째 소수일 때 바로 멈추고 출력해준다.K 값의 최대 범위를 보면 50만인데, 50만번째 소수는 7,368,787이다.따라서 소수 구하는 범위는 7500000까지로 지정하여 입력 범위 내 모든 소수를 찾을 수 있도..
문제 링크 : https://www.acmicpc.net/problem/1500#include using namespace std;const int MOD = 1000000007;int main() { int S, K; cin >> S >> K; int tmp1 = S/K; int tmp2 = S%K; long long result = 1; for(int i=0; i 0) { result*=(tmp1+1); tmp2--; } else result *= tmp1; } cout K개를 맞춰야 하므로, 우선 S/K를 통해 평균 값을 구해준다.이후 S%K를 통해 나머지 누락된..
문제링크 : https://www.acmicpc.net/problem/2622#include using namespace std;const int MOD = 1000000007;int arr[51];int main() { int N, cnt=0; cin >> N; for(int i=1; itmp) cnt++; } } cout 삼각형의 조건은, 가장 큰 변의 길이가 나머지 두 변의 합보다 작아야 한다는 것이다.따라서 2중 반복문을 통해 가장 큰 변을 하나 고정시켜놓고, 값 조절을 통해 가능한 경우를 모두 카운팅한다.
문제링크 : https://www.acmicpc.net/problem/13251#include using namespace std;const int MOD = 1000000007;int arr[51];int main() { int M, K; int sum = 0; cin >> M; for(int i=0; i> arr[i]; sum += arr[i]; } cin >> K; double result = 0; for(int i=0; i 먼저 뽑은 조약돌이 모두 같은 색일 확률을 구하기에, 입력받은 조약돌의 모든 개수를 구해준다.그리고 기본적으로 조약돌의 개수가 K보다 작다면 아에 불가능한 케이스이기에 스킵한다. 기본적으로는 arr[i]/sum이 기..
문제링크 : https://www.acmicpc.net/problem/1124#include using namespace std;const int MOD = 1000000007;int arr[100001];bool check(int n){ if(n> A >> B; vector prime; memset(arr, 1, sizeof(arr)); for(int i=2; i 에라스토테네스의 체를 활용해 우선 입력범위 만큼 소수체크를 해준다.이때 주의할점은 j=i*i가 아니라, j=i*2로 하는 것이다.j=i*i를 하면 i 값에 따라 int 범위를 벗어나 오버플로우가 발생한다.따라서 효율성이 약간 떨어지더라도 j=i*2를 선택해주었다. 이후로는 A~B까지 각 값에 대해서 미리 판별한 소수에 ..
#include #include using namespace std;long long solution(int cap, int n, vector deliveries, vector pickups) { long long answer = 0; long long d = 0, p = 0; for(int i=n-1; i>=0; i--) { int cnt = 0; d -= deliveries[i]; p -= pickups[i]; while(d 그리디하게 접근하여 풀 수 있는 문제이다.배달과 수거에 대한 변수를 따로 두고, 끝에서부터 배달해야 하는 값과 수거해야 하는 값을 체크한다.이후 반복문을 통해 cap의 수치만큼 더해가며,..
#include #include #include #include #include using namespace std;typedef long long ll;vector solution(vector> line) { set> points; //중복 없이 저장 ll minX = 1e18, maxX = -1e18, minY = 1e18, maxY = -1e18; for (int i = 0; i answer(h, string(w, '.')); //.으로 채우기 for (auto i : points) //해당 좌표만 * 처리 { ll r = maxY - i.second; ll c = i.first - minX; answer[r][c] = '..
#include #include #include using namespace std;int solution(int h1, int m1, int s1, int h2, int m2, int s2) { int answer = 0; int sTime = h1 * 3600 + m1 * 60 + s1; int eTime = h2 * 3600 + m2 * 60 + s2; if (sTime == 0 || sTime == 12 * 3600) answer++; while (sTime = hNext) answer++; if (sCur = mNext) answer++; if (abs(sNext - mNext) 주어진 시, 분, 초 에 대해서 시작 시간과 끝 시간 값을 따로..