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. SDK Manager.exe闪退

    运行tools文件下android.bat. 修改tools文件下android.bat文件,再运行SDK Manager.exe

  2. mvc ef LINQ to Entities 不识别方法“Int32 Parse(System.String)”,因此该方法无法转换为存储表达式。

    private sys_User GetUserInfo() { sys_User model = null; var userId = Convert.ToInt32(AccountHelper.G ...

  3. 阿里云服务器Linux CentOS安装配置(七)域名解析

    阿里云服务器Linux CentOS安装配置(七)域名解析 1.购买域名 登录阿里云,左侧菜单点击[域名],然后[域名注册],完成域名购买.(一般首年45元) 2.添加域名解析 在域名列表里点击你的域 ...

  4. OpenGL函数思考-glLoadIdentity

    函数原型: void glLoadIdentity(void) 函数说明: OpenGL为我们提供了一个非常简单的恢复初始坐标系的手段,那就是调用glLoadIdentity()命令.该命令是一个无参 ...

  5. JAVA算法

    一.归并排序  归并排序 (merge sort) 是一类与插入排序.交换排序.选择排序不同的另一种排序方法.归并的含义是将两个或两个以上的有序表合并成一个新的有序表.归并排序有多路归并排序.两路归并 ...

  6. 加快ArcGIS Server创建缓存速度,CachingTools的实例数

    大比例尺的缓存,由于文件非常大,创建非常花费时间,在硬件设备已固定的情况下,调整Caching tools的实例数是加快创建缓存的方法之一. 简单来说:CachingTools的最大并行实例数决定了C ...

  7. Java中MyEclipse快捷键整理

    ************************************  MyEclipse 快捷键1(CTRL) ************************************ Ctrl ...

  8. LeetCode Verify Preorder Sequence in Binary Search Tree

    原题链接在这里:https://leetcode.com/problems/verify-preorder-sequence-in-binary-search-tree/ 题目: Given an a ...

  9. python图片添加水印(转载)

    转载来自:http://blog.csdn.net/orangleliu/ # -*- encoding=utf-8 -*- ''''' author: orangleliu pil处理图片,验证,处 ...

  10. jqurey datatable tableTools 自定义button元素 以及按钮自事件

    版本 1.10.4 "dom": 'T<"clear">lfrtip', "tableTools": { //"sSw ...