UVa11292 The Dragon of Loowater

  原题链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2267

  谨以此水题标志开始《算法竞赛入门经典——训练指南》的学习。

View Code
 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <algorithm>
 4 #define N 20005
 5 
 6 int a[N], b[N];
 7 
 8 int main()
 9 {
10     int i, j, n, m, ans;
11     while(scanf("%d%d", &n, &m) == 2)
12     {
13         if(n == 0 && m == 0)
14             break;
15         for(i = 0; i < n; i ++) scanf("%d", &a[i]);
16         for(i = 0; i < m; i ++) scanf("%d", &b[i]);
17         std::sort(a, a + n);
18         std::sort(b, b + m);
19         for(ans = i = j = 0; i < n && j < m;)
20         {
21             if(b[j] >= a[i])
22                 ans += b[j], i++, j++;
23             else
24                 j ++;
25         }
26         if(i == n)
27             printf("%d\n", ans);
28         else
29             printf("Loowater is doomed!\n");
30     }
31     return 0;
32 }
原文地址:https://www.cnblogs.com/huangfeihome/p/2749353.html