UVA - 11292 Dragon of Loowater 贪心
贪心策略:一个直径为X的头颅,应该让雇佣费用满足大于等于X且最小的骑士来砍掉,这样才能使得花费最少。
AC代码
- #include <cstdio>
- #include <cmath>
- #include <algorithm>
- #include <cstring>
- #include <utility>
- #include <string>
- #include <iostream>
- #include <map>
- #include <set>
- #include <vector>
- #include <queue>
- #include <stack>
- using namespace std;
- #pragma comment(linker, "/STACK:1024000000,1024000000")
- #define eps 1e-10
- #define inf 0x3f3f3f3f
- #define PI pair<int, int>
- typedef long long LL;
- const int maxn = 2e4 + 5;
- int head[maxn], kill[maxn];
- int main() {
- int n, m;
- while(scanf("%d%d", &n, &m) == 2 && n && m) {
- for(int i = 0; i < n; ++i) scanf("%d", &head[i]);
- for(int i = 0; i < m; ++i) scanf("%d", &kill[i]);
- sort(head, head + n);
- sort(kill, kill + m);
- int cnt = 0, cost = 0;
- for(int i = 0; i < m; ++i) {
- if(kill[i] >= head[cnt]) {
- ++cnt;
- cost += kill[i];
- if(cnt >= n) break;
- }
- }
- if(cnt < n) printf("Loowater is doomed!\n");
- else printf("%d\n", cost);
- }
- return 0;
- }
如有不当之处欢迎指出!
UVA - 11292 Dragon of Loowater 贪心的更多相关文章
- UVA 11292 Dragon of Loowater(简单贪心)
Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance tur ...
- uva 11292 Dragon of Loowater (勇者斗恶龙)
Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance tur ...
- [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 ...
- UVa 11292 - Dragon of Loowater(排序贪心)
Once upon a time, in the Kingdom of Loowater, a minor nuisance turned into a major problem.The shore ...
- UVa 11292 Dragon of Loowater
简单贪心 龙头的直径和人的佣金排序,价值小的人和直径小的配 #include<iostream> #include<cstdio> #include<cmath> ...
- UVa 11292 Dragon of Loowater (水题,排序)
题意:有n个条龙,在雇佣勇士去杀,每个勇士能力值为x,只能杀死头的直径y小于或等于自己能力值的龙,只能被雇佣一次,并且你要给x赏金,求最少的赏金. 析:很简单么,很明显,能力值高的杀直径大的,低的杀直 ...
- UVA它11292 - Dragon of Loowater
Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance tur ...
- uva 11292 The Dragon of Loowater(贪心)
题目大意: 你的王国里有一条n个头的恶龙,你希望雇一些骑士把它杀死(即砍掉所有头).村里有m个骑士可以雇佣,一个能力值为x的骑士可以砍掉恶龙一个直径不超过x的头,且需要支付x个金币.如何雇佣骑士才 ...
- 贪心/思维题 UVA 11292 The Dragon of Loowater
题目传送门 /* 题意:n个头,m个士兵,问能否砍掉n个头 贪心/思维题:两个数组升序排序,用最弱的士兵砍掉当前的头 */ #include <cstdio> #include <c ...
随机推荐
- Windows任务计划程序起始于参数自动修改
Windows任务计划程序建立后,手工运行可以成功,但计划任务自动运行却不能成功,搜索网络,原来是起始于参数没有配置,这个参数的英文名字是start-in.它保证任务计划程序的WorkingDirec ...
- Navicat查询结果不能修改的原因
问题: 开发中常使用Navicat查询数据库,并修改数据库中的值.今天发现查询结果为只读,不能修改.一般连表查不能修改我是知道的,但是单表查居然不能修改. 解决方法: 查了下,有说表是只读,也有说是权 ...
- jspf与jsp的区别
如果想把一个jspf的文件引入(incurred)到一个jsp页面中,只能使用"@include"指令引入 如果使用<jsp:include>引入,jspf文件中的内容 ...
- javascript:将URL的参数列表解析为一个对象
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- HARBOR 仓库 API功能接口
1 项目管理 1.1 查看仓库中项目详细信息 curl -u "admin:Harbor12345" -X GET -H "Content-Type: ...
- 树莓派小车By 树莓派爱好者ITJoker(通过python socket通信实现树莓派视频小车)(一)
本文由树莓派爱好者ITJoker 编辑,转载请注明出处.本人也有新浪博客同样是树莓派爱好者ITJoker 所需材料:树莓派2B或者2B以上,L2985n驱动板,若干排线,电池及电池盒,usb无线网卡( ...
- SQL Server比较2table字段的差异
由于项目前后用了2个数据库,需要统计数据库结构的变化,需要统计每个表的变化,由于人工核对挺浪费时间,就写了一点代码: 1.统计表的字段数量(查询表有多少列): select count(name) ...
- JUnit5 技术前瞻
更多原创测试技术文章同步更新到微信公众号 :三国测,敬请扫码关注个人的微信号,感谢! 原文链接:http://www.cnblogs.com/zishi/p/6868495.html JUnit ...
- sap中Excel的模版上传和下载
一:事物码smw0 二:上传步骤 注:"包"为项目的包的名称. 三:下载代码 l_filename = 'XX.xls'. l_muban = 'z123'. *&---下 ...
- Spring整合JMS(二)——三种消息监听器
原文地址:http://haohaoxuexi.iteye.com/blog/1893676 1.3 消息监听器MessageListener 在Spring整合JMS的应用中我们在定义消息监 ...