백준

· 백준
코드#include #include #include using namespace std;int main() { int n; cin >> n; int caseNum = 1; while (n--) { int money; cin >> money; vector prices(13); // 1-based indexing for prices for (int i = 1; i > prices[i]; } int maxProfit = 0; // 최대 이익 int bestBuy = 0, bestSell = 0; // 최적의 구매/판매 월 bool found = false; // 유효한 결과가 있는지 여부 ..
· 백준
코드#include #include #include using namespace std;int n, a[1003], res = INT_MAX;void FASTIO() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);}int main() { FASTIO(); cin >> n; for (int i = 0; i > a[i]; } sort(a, a + n); // 가능한 모든 구간 탐색 for (int low = 0; low high) { cost += (a[i] - high) * (a[i] - high); } } r..
· 백준
코드#include #include #include #include #include #include using namespace std;int n, a[1500];void FASTIO() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);}int main() { FASTIO(); while(1) { cin >> n; fill(a, a + 1500, 0); if(!n) break; for(int i = 0; i > tmp; a[tmp] = 1; } int can = 200; // 충전 int dist = 0..
· 백준
코드#include #include #include #include #include #include using namespace std;int cnt, n, k;unordered_map mp;string s;vector> v;vector res;void FASTIO() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);}bool cmp(pair a, pair b) { return a.second > k >> n; for(int i = 0; i > s; mp[s] = ++cnt; } for(const auto& e : mp) { v.push_back(make_pair(e.fir..
· 백준
코드#include using namespace std;int tc, _a1, _p1, _r1, _p2;void FASTIO() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);}int gcd(int x, int y) { int tmp = x; while(y > 0) { x = y; y = tmp % y; } return x;}int main() { FASTIO(); cin >> tc; while(tc--) { cin >> _a1 >> _p1 >> _r1 >> _p2; int g = gcd(_p1, _p2); int lc..
· 백준
코드#include #include #include #include using namespace std;int n, num;string name, res;deque> dq;void FASTIO() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);}int main() { FASTIO(); cin >> n; // 입력 for(int i = 0; i > name >> num; dq.push_back(make_pair(name, num)); } // 덱의 크기가 1일 때 종료 while(1) { if(dq.size() == 1) { // 김한양의 최애..
· 백준
코드#include #include using namespace std;string s;void FASTIO() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);}int main() { FASTIO(); while(getline(cin, s)) { // 대문자를 소문자로 바꾸기 for(int i = 0; i = 65 && s[i] string::npos // long long으로 저장 long long idx = 0; idx = s.find("problem"); // string::npos가 아니면 찾는 값이 있는 것 if(i..
· 백준
코드#include using namespace std;int n, m, k;int main() { cin >> n >> m >> k; // 음수나 0인 경우 양수로 바꿔주기 while(k n) { k -= n; } // 3모가 기준 k -= 3; // 절대값 m = abs(m + k); m %= n; // 나머지가 0이면 n if(!m) m = n; cout 풀이음수 포함이라 헷갈려서 while 문을 이용해 노가다로 풀었다. 사실 수학 문제라 한 줄로 해결할 수 있겠지만... 이런 문제는 도통 어떻게 해야할지 몰라서 비효율적으로 풀었다. result = ((M - 1) + (k - 3) % N + N) % N + 1;이렇게 ..
· 백준
코드#include #include #include #include using namespace std;// 소수 목록을 저장할 벡터vector prime;// 에라토스테네스의 체로 소수 계산void sieve() { int max_limit = 316; // sqrt(100,000) vector is_prime(max_limit + 1, true); is_prime[0] = is_prime[1] = false; // 0과 1은 소수가 아님 for (int i = 2; i * i > tc; sieve(); // 소수 미리 계산 while (tc--) { int n; cin >> n; map factors; // 소인수와 지수를 저장 ..
· 백준
코드#include #include #include #include #include #include using namespace std;struct Query { int L, R, idx;};const int MAX_N = 300003;int n, c, a[MAX_N], m, max_cnt, max_num, freq[10001];void add(int x) { freq[x]++;}void remove(int x) { freq[x]--;}void FASTIO() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);}int main() { FASTIO(); cin >> n >> c; for (int i = 0; i > a[i]; int blo..