zoukankan      html  css  js  c++  java
  • 贪心/思维题 UVA 11292 The Dragon of Loowater

    题目传送门

     1 /*
     2     题意:n个头,m个士兵,问能否砍掉n个头
     3     贪心/思维题:两个数组升序排序,用最弱的士兵砍掉当前的头
     4 */
     5 #include <cstdio>
     6 #include <cstring>
     7 #include <algorithm>
     8 using namespace std;
     9 
    10 const int MAXN = 2e4 + 10;
    11 const int INF = 0x3f3f3f3f;
    12 int a[MAXN], b[MAXN];
    13 
    14 int main(void)        //UVA 11292 The Dragon of Loowater
    15 {
    16 //    freopen ("A.in", "r", stdin);
    17 
    18     int n, m;
    19     while (scanf ("%d%d", &n, &m) == 2)
    20     {
    21         if (n == 0 && m == 0)    break;
    22         for (int i=1; i<=n; ++i)    scanf ("%d", &a[i]);
    23         for (int i=1; i<=m; ++i)    scanf ("%d", &b[i]);
    24 
    25         sort (a+1, a+1+n);
    26         sort (b+1, b+1+m);
    27 
    28         int ans = 0;
    29         int i = 1, j = 1;
    30         while (i <= n && j <= m)
    31         {
    32             if (a[i] <= b[j])    {ans += b[j];    i++; j++;}
    33             else    j++;
    34         }
    35 
    36         if (i == n + 1 && j <= m + 1)    printf ("%d
    ", ans);
    37         else    puts ("Loowater is doomed!");
    38     }
    39 
    40     return 0;
    41 }
    42 
    43 /*
    44 Loowater is doomed!
    45 */

    /*题意:n个头,m个士兵,问能否砍掉n个头    贪心/思维题:两个数组升序排序,用最弱的士兵砍掉当前的头*/#include <cstdio>#include <cstring>#include <algorithm>using namespace std;
    const int MAXN = 2e4 + 10;const int INF = 0x3f3f3f3f;int a[MAXN], b[MAXN];
    int main(void)//UVA 11292 The Dragon of Loowater{//freopen ("A.in", "r", stdin);
    int n, m;while (scanf ("%d%d", &n, &m) == 2){if (n == 0 && m == 0)break;for (int i=1; i<=n; ++i)scanf ("%d", &a[i]);for (int i=1; i<=m; ++i)scanf ("%d", &b[i]);
    sort (a+1, a+1+n);sort (b+1, b+1+m);
    int ans = 0;int i = 1, j = 1;while (i <= n && j <= m){if (a[i] <= b[j]){ans += b[j];i++; j++;}elsej++;}
    if (i == n + 1 && j <= m + 1)printf ("%d ", ans);elseputs ("Loowater is doomed!");}
    return 0;}
    /*Loowater is doomed!*/

    编译人生,运行世界!
  • 相关阅读:
    node中__dirname、__filename、process.cwd()、process.chdir()表示的路径
    formidable模块的使用
    对象函数的readFileSyc类
    nodejs的事件驱动理解
    书籍类
    Cookie的弊端
    Codeforces 1015 E(模拟)
    Codeforces 1015D(贪心)
    牛客网暑期ACM多校训练营(第五场)I(树状数组)
    2018牛客暑假多校第五场 A(二分答案)
  • 原文地址:https://www.cnblogs.com/Running-Time/p/4644716.html
Copyright © 2011-2022 走看看