본문 바로가기

알고리즘/그리디 알고리즘34

1202 보석도둑 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667#include #include #include #include #include using namespace std; vector jew;vector bag; bool compare(pair a, pair b) { if (a.first > b.first) { return false; } else if (a.first 2019. 8. 29.
1781 컵라면 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354#include #include #include #include #include using namespace std; vector arr; bool compare(pair a, pair b) { if (a.first == b.first) { return a.second > b.second; } else if (a.first > b.first) { return true; } else { return false; }} int main() { int n, line = 0; scanf("%d", &n); for (int i = 0; i 2019. 8. 29.
1543 문서정리 123456789101112131415161718192021222324252627282930313233343536373839404142434445#include #include #include using namespace std; char str[2600];char part[55]; int main() { cin.getline(str, 2600); cin.getline(part, 55); int len = 0, l = 0, flag = 0; for (int i = 0; i 2019. 7. 1.
1969 DNA 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768#include int check[55][10] = { 0 };int dist[1005][55] = { 0 }; int main() { int n, m; scanf("%d %d", &n, &m); for (int i = 0; i 2019. 7. 1.
2873 롤러코스터 (재풀이 필요) 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153#include int arr[1005][1005] = { 0 }; int main(.. 2019. 6. 30.
9576 책 나눠주기 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465#include #include #include using namespace std; int from[1005];int student[1005];vector adj[1005]; int dfs(int x) { if (student[x] == 1) return 0; student[x] = 1; for (int i = 0; i 2019. 6. 29.
2188 축사 배정 (이분 매칭) 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061#include #include #include using namespace std; vector adj;int from[100000] = { 0 };int visit[100000] = { 0 }; int dfs(int x) { if (visit[x] == 1) { return 0; } visit[x] = 1; for (int i = 0; i 2019. 6. 29.
2262 토너먼트 만들기 (복습 필요. 왜 그리디?) 1234567891011121314151617181920212223242526272829303132#include #include using namespace std; int arr[100000] = { 0 };int check[1000000] = { 0 }; int main() { int n; scanf("%d", &n); for (int i = 1; i 1; i--) { int j; for (j = 1; j 2019. 6. 29.
2828 사과담기 게임 123456789101112131415161718192021222324252627282930313233#include int arr[100000] = { 0 }; int main() { int n, m, t; scanf("%d %d %d", &n, &m, &t); int l = 1, r = m; int rst = 0; while (t--) { int num; scanf("%d", &num); if (num 2019. 6. 28.
2816 디지털 티비 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273#include #include #include #include using namespace std; vector arr; int main() { int n; scanf("%d", &n); while (n--) { string str; cin >> str; if (str == "KBS1") { arr.push_back(1); } else if (str == "KBS2") { arr.push_back(2); } else { arr.push_back(0); } } i.. 2019. 6. 28.
12018 yonsei toto #include #include using namespace std;int arr[105] = { 0 };bool desc(int a, int b) {return a > b;}int main() {int t, point, idx = 0;scanf("%d %d", &t, &point);while (t--) {int all, can;scanf("%d %d", &all, &can);int temp[105] = { 0 };for (int i = 0; i 2019. 6. 28.
1439 뒤집기 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364#include #include using namespace std; char arr[1000005] = { 0 };int num[1000005]; int main() { scanf("%s", &arr); int len = 0; for (int i = 0; i 2019. 6. 28.