본문 바로가기

백준/실버

(285)
[백준 1246번] 온라인 판매 (C++) 문제링크 : https://www.acmicpc.net/problem/1246 #include using namespace std;typedef long long ll;typedef pair pii;const int MAX = INT_MAX;int N, M, arr[1001];int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> N >> M; for(int i=0; i> arr[i]; sort(arr, arr+M);; int tmp = 0; int idx = 0; for(int i=1; i 먼저 입력받은 금액에 대해서 정렬을 해준다.정렬된 값을 기준으로 가장 큰 값부터 현재 인덱스를 기준으로 가장 큰 값을 찾아..
[백준 1485번] 정사각형 (C++) 문제링크 : https://www.acmicpc.net/problem/1485 #include using namespace std;typedef long long ll;typedef pair pii;const int MAX = INT_MAX;int T, x, y;int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> T; while(T--) { vectorv; vectorresult; for(int i=0; i> x >> y; v.push_back({x, y}); } for(int i=0; i 모든 변의 길이가 같고(0~3) 대각선의 길이가 같음(..
[백준 2659번] 십자카드 문제 (C++) 문제링크 : https://www.acmicpc.net/problem/2659 #include using namespace std;typedef long long ll;typedef pair pii;const int MAX = INT_MAX;int a, b, c, d;bool visited[9999];int func(int a, int b, int c, int d) //제일 작은 시계수 구하기{ int num1 = a*1000 + b*100 + c*10 + d; int num2 = b*1000 + c*100 + d*10 + a; int num3 = c*1000 + d*100 + a*10 + b; int num4 = d*1000 + a*100 + b*10 + c; return m..
[백준 11536번] 줄 세우기 (C++) 문제링크 : https://www.acmicpc.net/problem/11536 #include using namespace std;typedef long long ll;typedef pair pii;const int MAX = INT_MAX;int N;string s;vectorv;vectorv1;vectorv2;int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> N; for(int i=0; i> s; v.push_back(s); v1.push_back(s); v2.push_back(s); } sort(v1.begin(), v1.end()); //오름차순 sort(v2.beg..
[백준 14729번] 칠무해 (C++) 문제링크 : https://www.acmicpc.net/problem/14729 #include using namespace std;typedef long long ll;typedef pair pii;const int MAX = INT_MAX;int N;vectorv;int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> N; for(int i=0; i> n; v.push_back(n); } sort(v.begin(), v.end()); cout  언뜻보면 간단한 정렬문제이지만, 출력 형식을 고려해야하는 문제이다.입력받는 수가 소수점 단위이므로 double 형으로 입력을 받도록 하였다. 이후 출력하기에 앞..
[백준 5648번] 역원소 정렬 (C++) 문제링크 : https://www.acmicpc.net/problem/5648#include using namespace std;typedef long long ll;typedef pair pii;const int MAX = INT_MAX;int N;string s;vectorv;int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> N; while(N--) { cin >> s; reverse(s.begin(), s.end()); v.push_back(stol(s)); //뒤집은 값 저장 } sort(v.begin(), v.end()); //뒤집은 값 정렬 for(int i=..
[백준 2535번] 아시아 정보올림피아드 (C++) 문제링크 : https://www.acmicpc.net/problem/2535#include using namespace std;typedef long long ll;typedef pair pii;const int MAX = INT_MAX;int N, n1, n2, n3;mapm;struct info{ int country; int student; int grade;};vectorv;bool cmp(info a, info b) //성적 순 정렬{ return a.grade > b.grade;}int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> N; for(int i=0; i> n1 >> n2 >> n3; ..
[백준 24417번] 알고리즘 수업 - 피보나치 수 2 (C++) 문제링크 : https://www.acmicpc.net/problem/24417#include using namespace std;typedef long long ll;typedef pair pii;const int MAX = INT_MAX;const int MOD = 1000000007;int N;int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> N; ll a = 1, b = 1; //더할 값 2가지 for(int i=2; i 언듯보면 웰노운으로 잘 알려진 dp 식을 이용해 피보나치를 푸는 문제이다.하지만 이렇게 풀 경우 N의 값이 최대 1억이기에 여기에만 메모리가 400MB가 사용되고,DP 중간 계산과정에서 추가적인 메..