본문 바로가기

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

11399 ATM 12345678910111213141516171819202122232425262728293031323334353637383940414243#include int arr[1001] = { 0 }; void qSort(int left, int right) { int l = left+1, r= right, num = arr[left]; do { while (arr[l] 2019. 6. 22.
테이블 옮기기 더블릿 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748#include #include #include #include #include #include using namespace std;vector table(300);priority_queue pq; bool compare(const pair& a, const pair& b) { if (a.first == b.first) return a.second 2019. 2. 20.
마감시간을 가지는 작업 더블릿 #include #include #include #include #include using namespace std;vector arr(20000);bool compare(const pair& a, const pair& b) {if (a.first == b.first)return a.second > b.second;return a.first > b.first;}int main() {int t, m, idx = 1;while (scanf("%d %d", &t, &m) != EOF) {arr[idx].first = t;arr[idx].second = m;idx++;}sort(&arr[1], &arr[idx], compare);int time = 0, rst = 0, end = arr[1].first;for .. 2019. 2. 20.
knapsack 더블릿 1234567891011121314151617181920212223242526272829303132333435363738394041#include #include #include #include #include using namespace std;vector mon(2000); bool compare(const pair& a, const pair& b) { if (a.second == b.second) return a.first > b.first; return a.second > b.second;} int main() { int w,n; scanf("%d %d", &w, &n); getchar(); for (int i = 1; i 0&&mon[i].first > w) { rst += (w * mon[i].. 2019. 2. 20.
mixing milk 더블릿 1234567891011121314151617181920212223242526272829303132333435363738#include #include #include #include using namespace std;vector company(6000); bool compare(const pair& a, const pair& b) { if (a.first == b.first) return a.second 2019. 2. 20.
(복습필요) 11000 강의실 배정 12345678910111213141516171819202122232425262728293031323334353637383940414243#include #include #include #include #include #include typedef long long ll;using namespace std;priority_queue pq;vector arr(300000); bool compare(const pair& a, const pair& b) { if (a.first == b.first) { return a.second 2019. 2. 19.
1931 회의실 배정 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849#include #include #include #include using namespace std;typedef long long ll;vector arr(200000); bool compare(const pair& a, const pair& b) { if (a.second == b.second) { if (a.first 2019. 2. 19.
11047 동전만들기 12345678910111213141516171819202122#include int arr[1000002] = { 0 }; int main() { int n, k,x; scanf("%d %d", &n, &k); int tmp = 0; for (int i = n; i >= 1; i--) { scanf("%d", &arr[i]); } for (int i = 1; i 2019. 2. 19.
1449 수리공 항승 12345678910111213141516171819202122232425#include #include using namespace std; int arr[2000] = { 0 }; int main(){ int n, l; scanf("%d %d", &n, &l); for (int i = 1; i 2019. 2. 19.
4796 캠핑 12345678910111213141516171819202122#include int upper[100] = { 0 };int down[100] = { 0 }; int main() { int idx = 1; while (1) { int n, a, b; scanf("%d %d %d", &n, &a, &b); if (n == 0) return 0; int rst=0; if ((b%a) > n) { rst = (b / a)*n + n; }else{ rst = (b / a)*n + (b%a); } printf("Case %d: %d\n", idx,rst); idx++; } }Colored by Color Scriptercs 2019. 2. 19.