题目传送门

 /*
题意:n个头,m个士兵,问能否砍掉n个头
贪心/思维题:两个数组升序排序,用最弱的士兵砍掉当前的头
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; const int MAXN = 2e4 + ;
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) == )
{
if (n == && m == ) break;
for (int i=; i<=n; ++i) scanf ("%d", &a[i]);
for (int i=; i<=m; ++i) scanf ("%d", &b[i]); sort (a+, a++n);
sort (b+, b++m); int ans = ;
int i = , j = ;
while (i <= n && j <= m)
{
if (a[i] <= b[j]) {ans += b[j]; i++; j++;}
else j++;
} if (i == n + && j <= m + ) printf ("%d\n", ans);
else puts ("Loowater is doomed!");
} return ;
} /*
Loowater is doomed!
*/

/*题意: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\n", ans);elseputs ("Loowater is doomed!");}
return 0;}
/*Loowater is doomed!*/

贪心/思维题 UVA 11292 The Dragon of Loowater的更多相关文章

  1. uva 11292 The Dragon of Loowater(贪心)

    题目大意:   你的王国里有一条n个头的恶龙,你希望雇一些骑士把它杀死(即砍掉所有头).村里有m个骑士可以雇佣,一个能力值为x的骑士可以砍掉恶龙一个直径不超过x的头,且需要支付x个金币.如何雇佣骑士才 ...

  2. UVa 11292 The Dragon of Loowater 【贪心】

    题意:有一条有n个头的恶龙,有m个骑士去砍掉它们的头,每个骑士可以砍直径不超过x的头,问怎样雇佣骑士,使花的钱最少 把头的直径从小到大排序,骑士的能力值也从小到大排序,再一个一个地去砍头 #inclu ...

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

    你的王国里有一条n个头的恶龙,你希望雇佣一些骑士把它杀死(也就是砍掉所有的头).村里有m个骑士可以雇佣,一个能力值为 x 的骑士可以砍掉恶龙一个直径不超过 x 的头,且需要支付 x 个金币.如何雇佣骑 ...

  4. UVA 11292 - The Dragon of Loowater (water)

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=sh ...

  5. 贪心/思维题 Codeforces Round #310 (Div. 2) C. Case of Matryoshkas

    题目传送门 /* 题意:套娃娃,可以套一个单独的娃娃,或者把最后面的娃娃取出,最后使得0-1-2-...-(n-1),问最少要几步 贪心/思维题:娃娃的状态:取出+套上(2),套上(1), 已套上(0 ...

  6. 思维题 UVA 10881 Piotr's Ants

    题目传送门 /* 题意:在坐标轴上一群蚂蚁向左或向右爬,问经过ts后,蚂蚁的位置和状态 思维题:本题的关键1:蚂蚁相撞看作是对穿过去,那么只要判断谁是谁就可以了 关键2:蚂蚁的相对位置不变 关键3:o ...

  7. ZOJ 3829 贪心 思维题

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3829 现场做这道题的时候,感觉是思维题.自己智商不够.不敢搞,想着队友智商 ...

  8. [ACM_水题] UVA 11292 Dragon of Loowater [勇士斗恶龙 双数组排序 贪心]

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

  9. 【贪心 思维题】[USACO13MAR]扑克牌型Poker Hands

    看似区间数据结构的一道题 题目描述 Bessie and her friends are playing a unique version of poker involving a deck with ...

随机推荐

  1. [K/3Cloud] 树形单据体的应用说明

    1.BOSIDE制作单据,支持动态表单,单据,基础资料,报表等域模型. 2.添加列,和原来单据体一样. 3.设置主键列名,父级主键字段名,行类型字段名,节点图片字段名(没有可以为空)   4.运行时展 ...

  2. mysql常用jar包

    连接Mysql数据库: 常用的连接池有两种 DBCP连接池 C3P0连接池 Apache的commons组件 -- DBCP连接池: commons-dbutils-1.4.jar 封装并简化了JDB ...

  3. IDUtil 永不重复的ID

    package com.xxx.common.util; import java.util.Random; /** * 各种id生成策略 * * @version 1.0 */ public clas ...

  4. JSP的会话(Session)跟踪

    以下内容引用自http://wiki.jikexueyuan.com/project/jsp/session-tracking.html: 会话(Session) HTTP是一个“无状态”协议,这意味 ...

  5. JSP的客户端请求

    以下内容引用自http://wiki.jikexueyuan.com/project/jsp/client-request.html: 当浏览器请求一个网页时,它向Web服务器发送大量的信息,信息不能 ...

  6. 【SQL Server 学习系列】-- 清除SQL Server 2012连接过的服务器名称

    需要删除两个地方,删除前请注意备份! 1.  %AppData%\Microsoft\Microsoft SQL Server\100\Tools\Shell\SqlStudio.bin 2.  %A ...

  7. centos 7 静态IP,指定DNS

    cd /etc/sysconfig/network-scripts/ 找到对应的网卡,配置并编辑 ls -l vim ifcfg-em1 配置例子: TYPE="Ethernet" ...

  8. Linux bash: scp: command not found的问题记录

    ,总结 scp成功,须要两个server都安装了scp服务才行.

  9. iOS学习笔记(4) — UITableView的 重用机制

    iOS学习笔记(4) — UITableView的 重用机制 UITableView中的cell是动态的,在使用过程中,系统会根据屏幕的高度(480)和每个cell的高度计算屏幕中需要显示的cell的 ...

  10. JavaScript你所不知道的困惑(1)

    困惑一: 先看一个样例: function test(){ message = "hi"; } test(); alert(message); 会输出字符串"hi&quo ...