hdu 5281 Senior's Gun(贪心)(思维)
来源:互联网 发布:mac电脑查看ip地址 编辑:程序博客网 时间:2024/03/29 01:04
Senior's Gun
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1608 Accepted Submission(s): 558
Problem Description
Xuejiejie is a beautiful and charming sharpshooter.
She often carriesn guns, and every gun has an attack power a[i] .
One day, Xuejiejie goes outside and comes acrossm monsters, and every monster has a defensive power b[j] .
Xuejiejie can use the guni to kill the monster j , which satisfies b[j]≤a[i] , and then she will get a[i]−b[j] bonus .
Remember that every gun can be used to kill at most one monster, and obviously every monster can be killed at most once.
Xuejiejie wants to gain most of the bonus. It's no need for her to kill all monsters.
She often carries
One day, Xuejiejie goes outside and comes across
Xuejiejie can use the gun
Remember that every gun can be used to kill at most one monster, and obviously every monster can be killed at most once.
Xuejiejie wants to gain most of the bonus. It's no need for her to kill all monsters.
Input
In the first line there is an integer T , indicates the number of test cases.
In each case:
The first line contains two integersn ,m .
The second line containsn integers, which means every gun's attack power.
The third line containsm integers, which mean every monster's defensive power.
1≤n,m≤100000 ,−109≤a[i],b[j]≤109 。
In each case:
The first line contains two integers
The second line contains
The third line contains
Output
For each test case, output one integer which means the maximum of the bonus Xuejiejie could gain.
Sample Input
12 22 32 2
Sample Output
1
虽然是稍微有点水的贪心题目,但是看看我的博客里边相关贪心的题解实在是少的可怜,这里就写出来供大家一起探讨。
题意还是比较好理解的,这里有一个小小的坑点:枪的数量,和怪物的数量,不一定是相等的,所以我们这里要特殊处理一下。
思路还是很好想通的,比田忌赛马相关问题简单了不少。没有那样复杂,我们这里直接拿最牛逼的枪干最差的怪物就行了:
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int gun[100010];int xue[101010];int main(){ int t; scanf("%d",&t); while(t--) { int n,m; scanf("%d%d",&n,&m); for(int i=0;i<n;i++) { scanf("%d",&gun[i]); } for(int i=0;i<m;i++) { scanf("%d",&xue[i]); } sort(gun,gun+n); reverse(gun,gun+n);//反向处理的方法之一~ sort(xue,xue+m); long long int sum=0; int minn=min(n,m); for(int i=0;i<minn;i++) { if(gun[i]>xue[i]) sum+=gun[i]-xue[i]; } printf("%lld\n",sum); }}
0 0
- hdu 5281 Senior's Gun(贪心)(思维)
- hdu 5281 Senior's Gun(贪心)
- HDU 5281 Senior's Gun 贪心
- hdu 5281 Senior's Gun
- HDU 5281 Senior's Gun
- hdu 5281 Senior's Gun
- hdu-5281 Senior's Gun*
- HDU 5281 Senior's Gun
- HDU 5281 Senior's Gun
- HDU 5281 Senior's Gun 杀怪
- HDU——5281 Senior's Gun
- HDU 5281 Senior's Gun——BestCoder Round #47(贪心)
- Senior's Gun-------(BestCoder Round #47)
- HDOJ5281 Senior's Gun(贪心思想)
- HDU 5281 BestCoder Round #47 1002:Senior's Gun
- hdu 5280 Senior's Array(dp)
- Bestcoder #47 B Senior's Gun
- HDU 6166 Senior Pan(思维 最短路)
- 第一篇文章。留个标记。
- 关于listview自定义滚动条和背景
- Python动态监控日志的内容
- javascript数组取值
- Environment Tree(环境树)
- hdu 5281 Senior's Gun(贪心)(思维)
- Dalvik虚拟机异常处理机制
- jsp 超链接跳转 弹出框提示是否操作
- hit-test的用法总结:如何阻止touch事件传递到子view
- 2016的路程--写给自己
- Android.mk文件分析
- Android 深入理解Android中的自定义属性
- 几个画图的js插件
- iOS开发:初识xib