본문 바로가기

C++

[백준] 33612번 피갤컵 C++ 코드 코드#includeint main(){ int n; scanf("%d",&n); n*=7; printf("%d %d",2024+n/12,n%12+1);}풀이n을 입력 받는다. 그 후 연도는 입력받은 n에서 12를 나눈 몫을 더해준다. 그리고 n에서 12를 나눈 나머지에서 1을 더해준 값을 넣어주면 된다. 1을 더하는 이유는, 12의 배수일 경우에 0이 나오기 때문에 이를 피해주기 위함이다. 하드코딩해서 풀이해도 된다. 더보기
[백준] 12109번 Hindeks C++ 코드 코드#include #include #include using namespace std;int n, a, res;priority_queue, greater> pq;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; pq.push(a); } while(!pq.empty()) { int tmp = pq.top(); // h-index 조건에 부합할 때 // 주어진 인용 수와 논문의 개수가 같을 때 if(tmp == .. 더보기
[백준] 12540번 Investing at the Market (Large) C++ 코드 코드#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; // 유효한 결과가 있는지 여부 .. 더보기
[백준] 9881번 Ski Course Design C++ 코드 코드#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.. 더보기
[백준] 4159번 알래스카 C++ 코드 코드#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.. 더보기
[백준] 13414번 수강신청 C++ 코드 코드#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.. 더보기
[백준] 26566번 Pizza C++ 코드 코드#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.. 더보기
[백준] 29813번 최애의 팀원 C++ 코드 코드#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) { // 김한양의 최애.. 더보기