HDU 5281 Senior's Gun (贪心)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5281
贪心题目,但是看看我的博客里边相关贪心的题解实在是少的可怜,这里就写出来供大家一起探讨。
题意还是比较好理解的,这里有一个小小的坑点:枪的数量,和怪物的数量,不一定是相等的,所以我们这里要特殊处理一下。
reverse函数:http://blog.sina.com.cn/s/blog_6d79d83a0100wh95.html
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <iostream>
#include <ctype.h>
#include <iomanip>
#include <queue>
#include <stdlib.h>
using namespace std; int a1[],a2[]; int main()
{
int t;
scanf("%d",&t);
while(t--){
int n,m;
scanf("%d %d",&n,&m);
for(int i=; i<n; i++){
scanf("%d",&a1[i]);
}
for(int i=; i<m; i++){
scanf("%d",&a2[i]);
} sort(a1,a1+n);
reverse(a1,a1+n);
sort(a2,a2+m); long long sum=;
int min1=min(n,m);
for(int i=; i<min1; i++){
if(a1[i]>a2[i]){
sum+=a1[i]-a2[i];
}
}
printf("%lld\n",sum);
}
}
HDU 5281 Senior's Gun (贪心)的更多相关文章
- hdu 5281 Senior's Gun
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5281 Senior's Gun Description Xuejiejie is a beautifu ...
- HDU 5281 Senior's Gun
Senior's Gun Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Tot ...
- HDU 5281 Senior's Gun 杀怪
题意:给出n把枪和m个怪.每把枪有一个攻击力,每一个怪有一个防御力.假设某把枪的攻击力不小于某个怪的防御力则能将怪秒杀,否则无法杀死.一把枪最多仅仅能杀一个怪,不能用多把枪杀同一个怪.每杀一次怪能够得 ...
- HDU 5281 BestCoder Round #47 1002:Senior's Gun
Senior's Gun Accepts: 235 Submissions: 977 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: ...
- hdu 4825 Xor Sum(trie+贪心)
hdu 4825 Xor Sum(trie+贪心) 刚刚补了前天的CF的D题再做这题感觉轻松了许多.简直一个模子啊...跑树上异或x最大值.贪心地让某位的值与x对应位的值不同即可. #include ...
- HDU Senior's Gun (水题)
题意: 给n把枪,m个怪兽,每把枪可消灭1怪兽,并获得能量=枪的攻击力-怪兽的防御力.求如何射杀能获得最多能量?(不必杀光) 思路: 用最大攻击力的枪杀防御力最小的怪兽明显可获得最大能量.如果每把枪都 ...
- hdu 5280 Senior's Array
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5280 Senior's Array Description One day, Xuejiejie ge ...
- HDU 5813 Elegant Construction (贪心)
Elegant Construction 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5813 Description Being an ACMer ...
- HDU 5802 Windows 10 (贪心+dfs)
Windows 10 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5802 Description Long long ago, there was ...
随机推荐
- TRIZ系列-创新原理-22-变害为利原理
变害为利原理的详细表述例如以下:1)利用有害的因素(特别是环境中的)获得积极的效果: 有害无害不过相对的(时间,空间,人),将有害的因素通过一定的处理和转化,能够变有害为实用,比方废品回收, ...
- 同一时候使用windows和linux系统
相信非常多人又想使用方便的windows,可是在开发中必须使用linux,怎样选择呢? 没关系,这里教你怎样制作双系统. 下载wubi,仅仅有几兆大,直接在windows下安装,安装好以后,双系统就制 ...
- C++习题 对象数组求最大值
Description 建立一个对象数组,内放n(<10)个学生的数据(学号.成绩),设立一个函数max,用指向对象的指针作函数参数,在max函数中找出n个学生中成绩最高者,并输出其学号. In ...
- 升级到tomcat8时Artifact SpringMvcDemo:war exploded: Server is not connected. Deploy is not
The method getDispatcherType() is undefined for the type HttpServletRequest 升级到tomcat8 http://segmen ...
- 2015-12-1 Visual Studio 2015 Update 1发布
http://news.cnblogs.com/n/533856/ 下载地址 文件名 cn_visual_studio_enterprise_2015_with_update_1_x86_x64_dv ...
- hibernate它5.many2one单向
关系数据库表之间的关系: 1 正确 1 1 正确 许多 许多 正确 许多 表间关系设计 基于主键关联 基于外键关联 基于中间表 1 对 1关系实现: 基于主键关联 基于外键关联 基于中间表 1 对 多 ...
- Windows Server 2008 R2 SP1 下载地址
Windows Server 2008 R2 SP1 http://download.microsoft.com/download/0/A/F/0AFB5316-3062-494A-AB78-7FB0 ...
- c# 判断字符是否是全角, 获取字符串的字节数 , 获取字符串指定长度字节数的字符串
1 Encoding.Default.GetByteCount(checkString); =2 全角 =1 半角 /// <summary> /// 获取字符串的字节长度 /// &l ...
- HDU 4916 树形dp
Count on the path Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Othe ...
- 从session实现机制分析模拟请求验证码的可行性(转)
悲剧了,发现写完这篇blog没有配上这个格调超高的标题. 1.0问题背景 现在要实现一个带验证码网站的的自动登陆功能.验证码识别过程不再这篇文章的讨论之中.(之后有篇文章我会详细的总结验证码的识别 ...