문제링크 : https://www.acmicpc.net/problem/15970 #include using namespace std;typedef long long ll;typedef pair pii;const int MAX = INT_MAX;int x, y, N, dis;vectorv[5001];int arr[5001]; //색 갯수 저장int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> N; for(int i=0; i> x >> y; v[y].push_back(x); arr[y]++; //색 갯수 카운팅 } for(int i=1; i 브루트포스 방식의 정렬문제이다.점과 색깔을 입력할 때, 입..
문제링크 : https://www.acmicpc.net/problem/14469 #include using namespace std;typedef long long ll;typedef pair pii;const int MAX = INT_MAX;int N, a, b;vectorv;int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> N; for(int i=0; i> a >> b; v.push_back({a, b}); } sort(v.begin(), v.end()); int time = v[0].first + v[0].second; for(int i=1; i 간단한 정렬문제이다.처음 도착시간을 기준으로..
문제링크 : https://www.acmicpc.net/problem/11256 #include using namespace std;typedef long long ll;typedef pair pii;const int MAX = INT_MAX;int T, J, N;int arr[10001];int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> T; while(T--) { int cnt = 0; //상자 갯수 cin >> J >> N; for(int i=0; i> r >> c; arr[i] = r*c; //크기 저장 } sort(arr, arr+N..
문제링크 : https://www.acmicpc.net/problem/1337#include using namespace std;typedef long long ll;typedef pair pii;const int MAX = INT_MAX;int N, arr[51];int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> N; for(int i=0; i> arr[i]; sort(arr, arr+N); int cnt = 1; for(int i=0; i 먼저 입력받은 배열에 대해 정렬해주고 시작한다.올바른 배열의 길이가 5이므로, 현재 값을 기준으로 최대 +4의 값까지 길이 확장이 가능하다.따라서 현재 위치의 값과 앞에 있..
문제링크 : 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 먼저 입력받은 금액에 대해서 정렬을 해준다.정렬된 값을 기준으로 가장 큰 값부터 현재 인덱스를 기준으로 가장 큰 값을 찾아..
문제링크 : 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) 대각선의 길이가 같음(..
문제링크 : 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..
문제링크 : 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..
문제링크 : 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 형으로 입력을 받도록 하였다. 이후 출력하기에 앞..
문제링크 : 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=..
문제링크 : 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; ..
문제링크 : 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 중간 계산과정에서 추가적인 메..
문제링크 : https://www.acmicpc.net/problem/16212#include using namespace std;typedef long long ll;typedef pair pii;const int MAX = INT_MAX;int N;int arr[500001];int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> N; for(int i=0; i> arr[i]; sort(arr, arr+N); for(int i=0; i 간단한 정렬 문제이다.힌트에 주어진 것 처럼 sort 함수를 사용하면 매우 간단하게 풀이가 가능하다.
문제링크 : https://www.acmicpc.net/problem/17271 17271번: 리그 오브 레전설 (Small)규환이는 리그 오브 레전설이라는 게임을 좋아한다. 이 게임에서는 N초의 시간 동안 싸움을 하는데, 규환이가 플레이하는 캐릭터는 A, B 두 가지 스킬을 사용할 수 있다. A 스킬의 시전 시간은 1www.acmicpc.net#include using namespace std;typedef long long ll;typedef pair pii;const int MAX = INT_MAX;int N, M;int dp[10001];const int MOD = 1000000007;int main(){ ios_base::sync_with_stdio(0); cin.tie(0); c..
문제링크 : https://www.acmicpc.net/problem/10431 10431번: 줄세우기 초등학교 선생님 강산이는 아이들을 데리고 단체로 어떤 일을 할 때 불편함이 없도록 새로 반에 배정받은 아이들에게 키 순서대로 번호를 부여한다. 번호를 부여할 땐 키가 가장 작은 아이가 1 www.acmicpc.net #include using namespace std; typedef long long ll; typedef pair pii; const int MAX = INT_MAX; int P, T, arr[21]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> P; while(P--) { cin >> T; int result = 0; f..