题目传送门

 /*
题意: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. 使用Spring-Session共享使用Session

    前言: session共享策略有很多,常见的有粘性复制,高并发下效率查.tomcat-redis-session-manager无疑是一个挺好的方案,缺点要配置tomcat,有点复杂.最优的方案莫过于 ...

  2. android listVIew实现button按钮监听程序

    1.重写simpleAdapter 方法@Override public HashMap<String,String> getItem(int position) { // TODO Au ...

  3. TYVJ1716 上帝造题的七分钟

    时间: 1000ms / 空间: 131072KiB / Java类名: Main 背景 裸体就意味着身体. 描述 “第一分钟,X说,要有矩阵,于是便有了一个里面写满了0的n×m矩阵.第二分钟,L说, ...

  4. 「CodePlus 2017 11 月赛」大吉大利,晚上吃鸡!

    n<=50000,m<=50000的图,给s和t,问有多少点对$(a,b)$满足 嗯. 不会. 首先最短路DAG造出来,然后两个条件转述一下:条件一,$N_a$表示从s到t经过a的路径,$ ...

  5. 基于 Java 的开源网络爬虫框架 WebCollector

    原文:https://www.oschina.net/p/webcollector

  6. redhat and centos 系统经常使用命令

    查看cpu信息:     more /proc/cpuinfo |grep "model name"     通常是至强系统 查看内存信息:     grep MemTotal / ...

  7. 又见古老的Typosquatting攻击:这次入侵Npm窃取开发者身份凭证

    有些攻击方式虽然听起来很幼稚,但有时候却也可以生效,比如typosquatting攻击——我们上次看到这种攻击是在去年6月份,这本身也是种很古老的攻击方式. 所谓的typosquatting,主要是通 ...

  8. modem&NIC&sound card

    Rate: Phone:8 k hz   radio:22050 hz Digital Video camcorder; miniDV; DAT LP mode:32 k hz Audio CD MP ...

  9. OpenFileDiag 使用

    MSDN模版 Stream myStream =null; OpenFileDialog openFileDialog1 =newOpenFileDialog(); openFileDialog1.I ...

  10. ASP.NET MVC Model之二模型绑定

    Asp.net mvc中的模型绑定,或许大家经常用,但是具体说他是怎么一回事,可能还是会有些陌生,那么,本文就带你理解模型绑定.为了理解模型绑定,本文会先给出其定义,然后对通过比,来得出使用模型绑定的 ...