题目链接: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 (贪心)的更多相关文章

  1. hdu 5281 Senior's Gun

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5281 Senior's Gun Description Xuejiejie is a beautifu ...

  2. HDU 5281 Senior&#39;s Gun

    Senior's Gun Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Tot ...

  3. HDU 5281 Senior&#39;s Gun 杀怪

    题意:给出n把枪和m个怪.每把枪有一个攻击力,每一个怪有一个防御力.假设某把枪的攻击力不小于某个怪的防御力则能将怪秒杀,否则无法杀死.一把枪最多仅仅能杀一个怪,不能用多把枪杀同一个怪.每杀一次怪能够得 ...

  4. 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: ...

  5. hdu 4825 Xor Sum(trie+贪心)

    hdu 4825 Xor Sum(trie+贪心) 刚刚补了前天的CF的D题再做这题感觉轻松了许多.简直一个模子啊...跑树上异或x最大值.贪心地让某位的值与x对应位的值不同即可. #include ...

  6. HDU Senior's Gun (水题)

    题意: 给n把枪,m个怪兽,每把枪可消灭1怪兽,并获得能量=枪的攻击力-怪兽的防御力.求如何射杀能获得最多能量?(不必杀光) 思路: 用最大攻击力的枪杀防御力最小的怪兽明显可获得最大能量.如果每把枪都 ...

  7. hdu 5280 Senior's Array

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5280 Senior's Array Description One day, Xuejiejie ge ...

  8. HDU 5813 Elegant Construction (贪心)

    Elegant Construction 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5813 Description Being an ACMer ...

  9. HDU 5802 Windows 10 (贪心+dfs)

    Windows 10 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5802 Description Long long ago, there was ...

随机推荐

  1. 玩转Web之Json(三)-----easy ui怎么把前台显示的dataGird中的所有数据序列化为json,返回到后台并解析

    最近做一个项目时,需要在dataGird中插入<input>,即文本输入框,当点击提交时,需要把文本框里填的数据返以及其他列的一些信息以json数组的格式返回到后台,虽然我实现了该功能,但 ...

  2. POJ - 3249 Test for Job (DAG+topsort)

    Description Mr.Dog was fired by his company. In order to support his family, he must find a new job ...

  3. [LeetCode82]Remove Duplicates from Sorted List II

    题目: Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct  ...

  4. MongoDB学习笔记-基础概念

    mongodb中基本的概念 文档.集合.数据库 与关系数据库的概念对比更容易理解

  5. Linux 环境下 Lua 安装(转)

    系统环境:CentOS-6.2-x86_64. Lua 是嵌入式脚本语言,应用场景很广泛. 引自官网:Lua is used in many products and projects around ...

  6. Python 显示LinkedIn用户作业

    CODE: #!/usr/bin/python # -*- coding: utf-8 -*- ''' Created on 2014-8-18 @author: guaguastd @name: j ...

  7. 微软研究院的分布式云计算框架orleans

    orleans   Orleans 客户端请求的消息流转以及消息在Silo中再路由机制 Witte 2015-04-29 21:58 阅读:196 评论:0     一种基于Orleans的分布式Id ...

  8. 终结者单身——setAccessible(true)

    首先看一下"传说"Singleton模式 package go.derek; public class Singleton{ public static int times; pr ...

  9. 解决Virtual Box 安装Mac OS X当出现“hfs: summary table not allowed on FS with block size of 2048”问题

    解决Virtual Box 安装Mac OS X当出现"hfs: summary table not allowed on FS with block size of 2048"问 ...

  10. UVA11396-Claw Decomposition(二分图判定)

    题目链接 题意:能否将一张无向连通图分解成多个爪型.每一条边仅仅能属于一个爪型,每一个点的度数为3. 思路:当图分解成类干个爪型时,每条边仅仅属于一个爪子,所以每条边的两个点一定要处于2个不同的鸡爪中 ...