HDU 5281 Senior's Gun
Senior's Gun
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 616 Accepted Submission(s): 241
She often carries n
guns, and every gun has an attack power a[i]
One day, Xuejiejie goes outside and comes across m
monsters, and every monster has a defensive power
b[j]
Xuejiejie can use the gun i
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.
T
indicates the number of test cases.
In each case:
The first line contains two integers n
m
The second line contains n
integers, which means every gun's attack power.
The third line contains m
integers, which mean every monster's defensive power.
1≤n,m≤100000
−10
1 2 2 2 3 2 2
1
题意:
- 有n把枪,m仅仅怪物。每把抢都有一个能量值。每一个怪物都有一个耗能值,如今用n把枪去打怪物,每把枪仅仅能用一次,怪物仅仅能打一次,用每i把枪打第j仅仅怪物得到能量值为a[i]-b[j],前提a[i]>=b[j],枪能够不用完,怪物也能够不打完,问最多能得多少的能量值。
- 解题:枚举用k把枪去打k仅仅怪物。那么每把枪都是最大能量值,每仅仅怪物都是耗能最少的。
- <pre name="code" class="cpp">#include<stdio.h>
- #include<algorithm>
- using namespace std;
- const int N = 100005;
- bool cmp(int a,int b){
- return a>b;
- }
- __int64 ans,a[N],b[N];
- int main()
- {
- int T,n,m;
- scanf("%d",&T);
- while(T--){
- scanf("%d%d",&n,&m);
- for(int i=0; i<n; i++)
- scanf("%I64d",&a[i]);
- for(int i=0; i<m; i++)
- scanf("%I64d",&b[i]);
- sort(a,a+n,cmp);
- sort(b,b+m);
- int k=0;
- ans=-(1<<29);
- while(k<n&&k<m){
- if(k!=0){
- a[k]+=a[k-1];
- b[k]+=b[k-1];
- }
- if(ans<a[k]-b[k])
- ans=a[k]-b[k];
- k++;
- }
- printf("%I64d\n",ans);
- }
- }
HDU 5281 Senior's Gun的更多相关文章
- HDU 5281 Senior's Gun 杀怪
题意:给出n把枪和m个怪.每把枪有一个攻击力,每一个怪有一个防御力.假设某把枪的攻击力不小于某个怪的防御力则能将怪秒杀,否则无法杀死.一把枪最多仅仅能杀一个怪,不能用多把枪杀同一个怪.每杀一次怪能够得 ...
- 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 (贪心)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5281 贪心题目,但是看看我的博客里边相关贪心的题解实在是少的可怜,这里就写出来供大家一起探讨. 题意还 ...
- Bestcoder #47 B Senior's Gun
Senior's Gun Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Tot ...
- hdu 5282 Senior's String 两次dp
题链:http://acm.hdu.edu.cn/showproblem.php?pid=5282 Senior's String Time Limit: 2000/1000 MS (Java/Oth ...
- HDU 5280 Senior's Array
Senior's Array Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) T ...
- HDU 5280 Senior's Array 最大区间和
题意:给定n个数.要求必须将当中某个数改为P,求修改后最大的区间和能够为多少. 水题.枚举每一个区间.假设该区间不改动(即改动该区间以外的数),则就为该区间和,若该区间要改动,由于必须改动,所以肯定是 ...
- 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 5280 Senior's Array
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5280 Senior's Array Description One day, Xuejiejie ge ...
随机推荐
- VS EF Error: Configuration Error extension=".edmx" type="System.Data.Entity.Design.AspNet.EntityDesignerBuildProvider"
错误截图: Configuration Error :<add extension=".edmx" type="System.Data.Entity.Design. ...
- C#操作Office.word(三)
前面两篇博客讲解了怎么通过程序控制word的生成,包括生成文字.添加表格.添加图片等.这篇博客主要说一下怎么把word图片转换成pdf. using System; using System.Coll ...
- windows 下提取目录下所有文件的文件名
tree D:/dir /f >D:/filenames.txt 提取D盘dir目录下所有文件名,写入文件filenames.txt
- 记录:sea.js和require.js配置 与 性能对比
最近有点忙,很久无写博客,记录一下之前的配置require.js和sea.js的配置.(有误有望提出 require.js 文件目录 /app(项目使用js) /lib(require.js jq存放 ...
- Oracle "Job定时"
今天需要做个定时器,定时到别的库导入数据用到了Job,第一次使用记录下来,如果有第一次操作的可以借鉴一下 1.首先,使用Toad新建job,进入配置页面
- DB2 VC++ 中连接字符串
根据你安装的驱动,有如下两种连接字符串形式.Provider=DB2OLEDB;Network Transport Library=TCPIP;Network Address=xxx.xxx.xxx. ...
- 我被SQL注入撞了一下腰
网站的注入漏洞,应该说绝大多数做web开发的人都知道的事情.可是没想到从事6,7年开发工作的我,却会在这上栽了跟头,真是郁闷啊.心情很纠结,按照老婆的话,怎么感觉我像失恋了一样. 事情的起因还是在几个 ...
- Android自定义控件(36篇)
http://blog.csdn.net/lmj623565791/article/details/44278417 http://download.csdn.net/user/lmj62356579 ...
- vs2010经常使用快捷键
调试快捷键 F6: 生成解决方式 Ctrl+F6: 生成当前项目 F7: 查看代码 Shift+F7: 查看窗口设计器 F5: 启动调试 Ctrl+F5: 開始运行(不调试) Shift+F5: 停止 ...
- mac下配置cocos2d-x3.0
今天看到3.0的正式版公布了,就马上荡下来试试3.0,以下记录下环境变量配置过程 打开用户文件夹下.bash_profile文件,配置环境 1.首先配置下android sdk,我的是在opt文件夹下 ...