zoukankan      html  css  js  c++  java
  • UVa11292勇者斗恶龙

    Once upon a time, in the Kingdom of Loowater, a minor nuisance turned into a major problem.

    The shores of Rellau Creek in central Loowater had always been a prime breeding ground for geese. Due to the lack of predators, the geese population was out of control. The people of Loowater mostly kept clear of the geese. Occasionally, a goose would attack one of the people, and perhaps bite off a finger or two, but in general, the people tolerated the geese as a minor nuisance.

    One day, a freak mutation occurred, and one of the geese spawned a multi-headed fire-breathing dragon. When the dragon grew up, he threatened to burn the Kingdom of Loowater to a crisp. Loowater had a major problem. The king was alarmed, and called on his knights to slay the dragon and save the kingdom.

    The knights explained: "To slay the dragon, we must chop off all its heads. Each knight can chop off one of the dragon's heads. The heads of the dragon are of different sizes. In order to chop off a head, a knight must be at least as tall as the diameter of the head. The knights' union demands that for chopping off a head, a knight must be paid a wage equal to one gold coin for each centimetre of the knight's height."

    Would there be enough knights to defeat the dragon? The king called on his advisors to help him decide how many and which knights to hire. After having lost a lot of money building Mir Park, the king wanted to minimize the expense of slaying the dragon. As one of the advisors, your job was to help the king. You took it very seriously: if you failed, you and the whole kingdom would be burnt to a crisp!

    Input Specification:

    The input contains several test cases. The first line of each test case contains two integers between 1 and 20000 inclusive, indicating the number n of heads that the dragon has, and the number m of knights in the kingdom. The next n lines each contain an integer, and give the diameters of the dragon's heads, in centimetres. The following m lines each contain an integer, and specify the heights of the knights of Loowater, also in centimetres.

    The last test case is followed by a line containing:

    0 0
    

    Output Specification:

    For each test case, output a line containing the minimum number of gold coins that the king needs to pay to slay the dragon. If it is not possible for the knights of Loowater to slay the dragon, output the line:

    Loowater is doomed!
    

    Sample Input:

    2 3
    5
    4
    7
    8
    4
    2 1
    5
    5
    10
    0 0
    

    Output for Sample Input:

    11
    Loowater is doomed!

    贪心;

    代码:
     1 #include<iostream>
     2 #include<string.h>
     3 #include<algorithm>
     4 #include<stdio.h>
     5 using namespace std;
     6 
     7 int a[20001],b[20001];
     8 
     9 int main()
    10 {
    11     int n,m;
    12     //freopen("aa.txt","r",stdin);
    13     while(cin>>n>>m)
    14     {
    15         if(n==0&&m==0)
    16             break;
    17         for(int i=0;i<n;i++)
    18             cin>>a[i];
    19         for(int i=0;i<m;i++)
    20             cin>>b[i];
    21         sort(a,a+n);
    22         sort(b,b+m);
    23         if(n>m)
    24         cout<<"Loowater is doomed!"<<endl;
    25         else
    26         {
    27             int num=0;
    28             int sum=0;
    29             int k=0;
    30             int x=0;
    31             for(int i=0;i<n;i++)
    32             {
    33                 for(int j=x;j<m;j++)
    34                 {
    35                     if(b[j]>=a[i])
    36                     {
    37                         num++;
    38                         sum+=b[j];
    39                         x=j+1;
    40                         break;
    41                     }
    42                     if(num==n)
    43                         break;
    44                 }
    45             }
    46             if(num==n)
    47                 cout<<sum<<endl;
    48             else
    49                 cout<<"Loowater is doomed!"<<endl;
    50         }
    51     }
    52     return 0;
    53 }
    View Code
  • 相关阅读:
    PY个树状数组
    PY 个板子计划【雾
    PY个欧拉筛
    【NOI2007】项链工厂 ——老题新做.jpg
    Min-Max 容斥的证明
    51nod 1963 树上Nim
    ●BZOJ 3566 [SHOI2014]概率充电器
    ●BZOJ 3640 JC的小苹果
    ●BZOJ 1444 [Jsoi2009]有趣的游戏
    ●Joyoi Dotp 驱逐猪猡
  • 原文地址:https://www.cnblogs.com/zhanzhao/p/3561624.html
Copyright © 2011-2022 走看看