LA 4636 Cubist Artwork

https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2637

  这题可以模拟贪心排布,也可以像我的代码一样,直接贪心。

代码如下:

View Code
 1 #define REP(i, n) for (int i = 0; i < (n); i++)
 2 
 3 int cnt[N];
 4 
 5 int main() {
 6     int w, d;
 7     while (~scanf("%d%d", &w, &d) && (w || d)) {
 8         _clr(cnt);
 9         int sum = 0, x;
10         REP(i, w) {
11             scanf("%d", &x);
12             cnt[x]++;
13         }
14         REP(i, d) {
15             scanf("%d", &x);
16             if (cnt[x] > 0) sum += x;
17             cnt[x]--;
18         }
19         REP(i, N) sum += abs(cnt[i] * i);
20         printf("%d\n", sum);
21     }
22     return 0;
23 }

——written by Lyon

原文地址:https://www.cnblogs.com/LyonLys/p/LA_4636_Lyon.html