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 ...
随机推荐
- 精致的外观Request
为什么要说Request精致的外观?请注意,我们这里所说的并不总是理解含义的外观门面,事实上,它使用的立面设计图案.使用的主要考虑数据安全的门面.它涉及到一个更大的系统系统的多个子系统之间的互动沟通. ...
- “ddl”有一个无效 SelectedValue,因为它不在项目列表中。
“ddl_ekt”有一个无效 SelectedValue,因为它不在项目列表中. 怎么回事 现象: 在用户控件的page_load事件里绑定下拉框,报上面错误 解决: 将下拉框绑定,放在page_In ...
- Unity 捕获IronPython脚本错误
using System; using System.Collections.Generic; using System.IO; using System.Reflection; using Syst ...
- 乐在其中设计模式(C#) - 状态模式(State Pattern)
原文:乐在其中设计模式(C#) - 状态模式(State Pattern) [索引页][源码下载] 乐在其中设计模式(C#) - 状态模式(State Pattern) 作者:webabcd 介绍 允 ...
- 【转】static_cast和reinterpret_cast
static_cast和reinterpret_cast揭秘 收藏 本文讨论static_cast<> 和 reinterpret_cast<>. reinterpret_ca ...
- vuejs 相关资料
官网 http://vuejs.org/ 中文网站 http://cn.vuejs.org/ Vue.js——60分钟快速入门 http://www.cnblogs.com/keepfool/p/56 ...
- 我学的是设计模式的视频教程——命令模式vs策略模式,唠嗑
课程视频 命令模式vs策略模式 唠嗑 课程笔记 课程笔记 课程代码 课程代码 新课程火热报名中 课程介绍 版权声明:本文博主原创文章,博客,未经同意不得转载.
- 【Android进阶】获取Android软件的版本信息
PackageInfo pinfo = getPackageManager().getPackageInfo("com.andbase", PackageManager.GET_C ...
- 为RadComboBox添加SelectionChanging事件
代码非标准,仅供参考. using System; using System.Collections.Generic; using System.Linq; using System.Windows. ...
- JAVA学习课第五十八届 — GUI
GUI Graghical User Interface(图形用户接口) java为GUI提供的对象都存在java.awt和java.swing包中 Java的GUI做的的确干只是C++等.不打算浪费 ...