话说这题。。。是贪心、、、
Orz JCVB(虽然这是hzwer的blog。。。Jcvb的不知道则么回事打不开。。。囧)
1 /************************************************************** 2 Problem: 1110 3 User: rausen 4 Language: C++ 5 Result: Accepted 6 Time:984 ms 7 Memory:1588 kb 8 ****************************************************************/ 9 10 #include <cstdio> 11 #include <cctype> 12 #include <algorithm> 13 14 using namespace std; 15 const int N = 100005; 16 const int M = 55; 17 18 int n, m, tot; 19 int a[N], b[N]; 20 int c[M], cnt[M]; 21 22 inline int read() { 23 int x = 0, sgn = 1; 24 char ch = getchar(); 25 while (!isdigit(ch)) { 26 if (ch == '-') sgn = -1; 27 ch = getchar(); 28 } 29 while (isdigit(ch)) { 30 x = x * 10 + ch - '0'; 31 ch = getchar(); 32 } 33 return sgn * x; 34 } 35 36 37 bool check(int now) { 38 int i; 39 for (i = now + 1; i <= tot; ++i) 40 if (cnt[i]) { 41 cnt[now] += c[i] / c[now]; 42 --cnt[i]; 43 return 1; 44 } 45 return 0; 46 } 47 48 int main() { 49 int i, j, now; 50 n = read(), m = read(); 51 for (i = 1; i <= n; ++i) 52 a[i] = read(); 53 for (i = 1; i <= m; ++i) 54 b[i] = read(); 55 sort(b + 1, b + m + 1); 56 for (i = 1; i <= m; ++i) 57 if (b[i] != b[i - 1]) c[++tot] = b[i]; 58 for (i = 1; i <= n; ++i) 59 for (j = tot; j; --j) 60 while (c[j] <= a[i]) 61 a[i] -= c[j], ++cnt[j]; 62 now = 1; 63 for (i = 1; i <= m; ++i) { 64 while (b[i] > c[now]) ++now; 65 if (cnt[now]) --cnt[now]; 66 else if (check(now)) --cnt[now]; 67 else { 68 printf("%d\n", i - 1); 69 return 0; 70 } 71 if (i == m) printf("%d\n", m); 72 } 73 return 0; 74 }
By Xs酱~ 转载请说明
博客地址:http://www.cnblogs.com/rausen