hdu 5281 Senior's Gun
来源:互联网 发布:马云八字 知乎 编辑:程序博客网 时间:2024/05/17 06:04
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5281
题目大意:学姐姐是一个酷酷的枪手。
她常常会随身携带n 把枪,每把枪有一个攻击力a[i] 。
有一天她遇到了m 只怪兽,每只怪兽有一个防御力b[j] 。现在她决定用手中的枪消灭这些怪兽。
学姐姐可以用第i 把枪消灭第j 只怪兽当且仅当b[j]≤a[i] ,同时她会获得a[i]−b[j] 的分数。
每把枪至多只能使用一次,怪兽死后也不会复活。现在学姐姐想知道她最多能得到多少分(她可以不用消灭所有的怪兽)。
解题思路:把a[i]从大到小排一下序,把b[i]从小到大排一下序,然后比较一下就行了
#include <iostream>#include <algorithm>#include <cstdio>using namespace std;const int maxn=100000+5;typedef long long LL;LL a[maxn],b[maxn];bool cmp(LL a, LL b){ return a>b;}int main(){ int T; scanf("%d",&T); int m,n; while(T--) { scanf("%d%d",&m,&n); for(int i=0; i<m; i++) scanf("%lld",&a[i]); sort(a,a+m,cmp); for(int i=0; i<n; i++) scanf("%lld",&b[i]); sort(b,b+n); //int minn=n<m?n:m; int minn=min(m,n); LL sum=0; for(int i=0; i<minn; i++) { if(a[i]>=b[i]) sum+=a[i]-b[i]; else break; } printf("%lld\n",sum); } return 0;}
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 BestCoder Round #47 1002:Senior's Gun
- hdu 5281 Senior's Gun(贪心)(思维)
- HDU 5281 Senior's Gun——BestCoder Round #47(贪心)
- Bestcoder #47 B Senior's Gun
- HDOJ5281 Senior's Gun(贪心思想)
- Senior's Gun-------(BestCoder Round #47)
- HDU 5280 Senior's Array
- hdu 5280 Senior's Array
- Linked List Cycle I II
- 看opengl写代码(3) 实现矩阵的旋转
- 贾玲版花木兰,文化行业恰到好处的反思
- 设计并测试一个名为Rectangle的矩形类
- Swift结构体和类
- hdu 5281 Senior's Gun
- 移植st官方usb-hid程序出现babble detected错误
- 设计动画函数的注意事项
- 定义一个Circle类,有数据成员Radius(半径)
- 17_Android中Broadcast详解(有序广播,无序广播)最终广播,Bundle传递参数,传递参数的时候指定权限
- 总结
- Error:java: Compilation failed: internal java comp
- C++中不能被重载的运算符介绍
- Linux 系统扫描技术及安全防范 之 mtr