贪心/思维题 UVA 11292 The Dragon of Loowater
/*
题意: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的更多相关文章
- uva 11292 The Dragon of Loowater(贪心)
题目大意: 你的王国里有一条n个头的恶龙,你希望雇一些骑士把它杀死(即砍掉所有头).村里有m个骑士可以雇佣,一个能力值为x的骑士可以砍掉恶龙一个直径不超过x的头,且需要支付x个金币.如何雇佣骑士才 ...
- UVa 11292 The Dragon of Loowater 【贪心】
题意:有一条有n个头的恶龙,有m个骑士去砍掉它们的头,每个骑士可以砍直径不超过x的头,问怎样雇佣骑士,使花的钱最少 把头的直径从小到大排序,骑士的能力值也从小到大排序,再一个一个地去砍头 #inclu ...
- UVa 11292 The Dragon of Loowater 勇者斗恶龙
你的王国里有一条n个头的恶龙,你希望雇佣一些骑士把它杀死(也就是砍掉所有的头).村里有m个骑士可以雇佣,一个能力值为 x 的骑士可以砍掉恶龙一个直径不超过 x 的头,且需要支付 x 个金币.如何雇佣骑 ...
- UVA 11292 - The Dragon of Loowater (water)
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=sh ...
- 贪心/思维题 Codeforces Round #310 (Div. 2) C. Case of Matryoshkas
题目传送门 /* 题意:套娃娃,可以套一个单独的娃娃,或者把最后面的娃娃取出,最后使得0-1-2-...-(n-1),问最少要几步 贪心/思维题:娃娃的状态:取出+套上(2),套上(1), 已套上(0 ...
- 思维题 UVA 10881 Piotr's Ants
题目传送门 /* 题意:在坐标轴上一群蚂蚁向左或向右爬,问经过ts后,蚂蚁的位置和状态 思维题:本题的关键1:蚂蚁相撞看作是对穿过去,那么只要判断谁是谁就可以了 关键2:蚂蚁的相对位置不变 关键3:o ...
- ZOJ 3829 贪心 思维题
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3829 现场做这道题的时候,感觉是思维题.自己智商不够.不敢搞,想着队友智商 ...
- [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 ...
- 【贪心 思维题】[USACO13MAR]扑克牌型Poker Hands
看似区间数据结构的一道题 题目描述 Bessie and her friends are playing a unique version of poker involving a deck with ...
随机推荐
- Spring data jpa 复杂动态查询方式总结
一.Spring data jpa 简介 首先我并不推荐使用jpa作为ORM框架,毕竟对于负责查询的时候还是不太灵活,还是建议使用mybatis,自己写sql比较好.但是如果公司用这个就没办法了,可以 ...
- tyvj1031 热浪
背景 USACO OCT09 9TH 描述 德克萨斯纯朴的民眾们这个夏天正在遭受巨大的热浪!!!他们的德克萨斯长角牛吃起来不错,可是他们并不是很擅长生產富含奶油的乳製品.Farmer John此时以先 ...
- codevs——1742 爬楼梯
1742 爬楼梯 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 题目描述 Description 小明家外面有一个长长的楼梯,共N阶.小明的 ...
- label显示不同颜色的字体
NSString *contentSrt = [NSString stringWithFormat:@"%@ (%@)",categoryModel.categoryName, c ...
- Xcode iOS9.3 配置包 iOS10.0 配置包 iOS10.2 配置包 could not find developer disk image
在Finder状态下前往目录.快捷键:shift+command+G,填写路径/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS ...
- javaWeb_使用标签库简化jsp
jsp标签库.也叫自己定义标签. 应用范围 jsp标签.主要应用于前台页面.在jsp中.假设jsp中存在<% %> 等 java代码.那么对前台开发者来说.就须要了解 java代码. 怎样 ...
- java.io.IOException: read failed, socket might closed or timeout, read ret: -1
近期项目中连接蓝牙之后接收蓝牙设备发出的指令功能,在连接设备之后,创建RfcommSocket连接时候报java.io.IOException: read failed, socket might c ...
- Maven手工安装jar包到本地仓库
使用maven,少不了的就是要被"包下载失败"这种问题折腾. jar包下载失败后.我们选择手工把jar下载下来.(能够下载到指定jar的途经非常多) 以下随便找了一个jar包为例. ...
- Linux 编译C++ 与 设置 Vim
1. Linux 下编译c++ vim test.cpp // 创建文件 g++ test.cpp // 编译文件 ./a.out // 执行文件 g++ test.cpp ...
- hdu 5256 序列变换
最长上升子序列 nlogn;也是从别人的博客学来的 #include<iostream> #include<algorithm> #define maxn 100000+5 u ...