https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=2267

有一条n个头的恶龙,现在有m个骑士可以雇佣去杀死他,一个能力值为x的勇士可以砍掉直径不超过x的头,而且需要支付x个金币。如何雇佣才能砍掉所有的头且支付最少的金币,注意一个勇士只能砍一个头,也只能被雇佣一次。

输入包含多组数据,每组数据第一行为正整数n,m(1<=n,m<=20000),以下n行每行为一个整数,就是恶龙的头的直径,以下m行每行为一个整数,就是每个骑士的能力值。输入结束标志位m=n=0。

输出格式对于每组数据输出最少花费,如果无解,则输出"Loowater is doomed!"。

输入样例

2 3

5

4

7

8

4

2 1

5

5

10

0 0

这个题意思是挺好理解的,就是x>=n,而且x不能重复使用,本来我是按照习惯

for(int i=0;i<n;i++)
       {
           for(j=0;j<m;j++)
           {
               if(b[j]>=a[i])
               {
                   s=s+b[j];
                   break;
               }
           }
       }

好吧,后来又想x只能用一次啊,然后就改成j=i,但是结果还是不对,然后想数据,发现还是不行,就看了一下书,他是把j放在前面的,

然后就改成了这个

#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int n,i,m,a[20000],b[20000];
    while(cin>>n>>m)
    {
        if(n==0&&m==0)
            break;
        int s=0;
        for(i=0;i<n;i++)
        {
            cin>>a[i];
        }
        for(int j=0;j<m;j++)
        {
            cin>>b[j];
        }
        sort(a,a+n);
        sort(b,b+m);
       for(int j=0;j<m;j++)
       {
           for(i=j;i<n;i++)
           {
               if(b[j]>=a[i])
               {
                   s=s+b[j];
                   break;
               }
           }
       }
        if(i<n||s==0)
        {
            cout<<"Loowater is doomed!"<<endl;
        }
        else
            cout<<s<<endl;
    }
    return 0;
}

最后判断输出什么是如果骑士的个数少于恶龙的头,那么无论怎么样都不行,如果s==0那也代表没办法

哎,好多天没打代码了,什么都忘了,今天下定决心好好好学。

勇者斗恶龙UVa11292 - Dragon of Loowater的更多相关文章

  1. uva11292 Dragon of Loowater

    水题,排序遍历即可 #include<iostream> #include<cstdio> #include<algorithm> using namespace ...

  2. uva11292 Dragon of Loowater(排序后贪心)

    #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #inc ...

  3. UVa 11292 勇者斗恶龙(The Dragon of Loowater)

    首先先看一下这道题的英文原版... 好吧,没看懂... 大体意思就是: 有一条n个头的恶龙,现在有m个骑士可以雇佣去杀死他,一个能力值为x的勇士可以砍掉直径不超过x的头,而且需要支付x个金币.如何雇佣 ...

  4. uva-----11292 The Dragon of Loowater

    Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance tur ...

  5. uva 11292 Dragon of Loowater (勇者斗恶龙)

    Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance tur ...

  6. The Dragon of Loowater

      The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance turned into ...

  7. UVA它11292 - Dragon of Loowater

    Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance tur ...

  8. UVA 11292 Dragon of Loowater(简单贪心)

    Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance tur ...

  9. Dragon of Loowater

    option=com_onlinejudge&Itemid=8&page=show_problem&problem=2267" style="color:b ...

随机推荐

  1. monkey命令

    介绍: monkey是一个命令行工具,可以运行在Android模拟器里或真实设备中.它可以向系统发送伪随机(pseudo-random)的用户事件流(如按键输入.触摸屏输入.手势输入等),可以对待测的 ...

  2. 在mvc中将session的值绑定在页面上

    第一步,在SqlServer数据库中创建存储过程,查询的是用户名(员工姓名)所扮演的角色: if exists(select * from sys.objects where name='proc_s ...

  3. 使用crypto模块实现md5加密功能(解决中文加密前后端不一致的问题)

    正常情况下使用md5加密 var crypto = require('crypto'); var md5Sign = function (data) { var md5 = crypto.create ...

  4. [转载]Difference between <context:annotation-config> vs <context:component-scan>

    在国外看到详细的说明一篇,非常浅显透彻.转给国内的筒子们:-) 原文标题: Spring中的<context:annotation-config>与<context:componen ...

  5. Jquery实现静态切换tab

    1. <div id="tabs"> <ul> <li><a href=</a></li> <li>& ...

  6. 在使用Intelligencia.UrlRewriter过程中 中文乱码问题

    由于业务需求,最近将项目部分模块修改为伪静态,使用到了Intelligencia.UrlRewriter.dll组件. 网上对使用Intelligencia.UrlRewriter.dll的配置讲解很 ...

  7. mongodb入门学习小记

    Mongodb 简单入门(个人学习小记) 1.安装并注册成服务:(示例) E:\DevTools\mongodb3.2.6\bin>mongod.exe --bind_ip 127.0.0.1 ...

  8. CSS技巧和经验:

    1. 如何清除图片下方出现几像素的空白间隙 方法1 img { display: block; } 方法2 img { vertical-align: top; } // 除了top值,还可以设置为t ...

  9. tomcat由浅入深

    零.服务器.Servlet容器.web容器 Servlet容器:能够运行Servlet的环境叫做Servlet容器 web容器:能够运行web应用的环境就叫做web容器 weblogic websph ...

  10. 如何让tomcat不记录catalina.out这个日志文件

    tomcat日志记录配置在conf/logging.properties中 有这5类日志 catalina,localhost,manager,admin(控制台),host-manager 还有8个 ...