HDU——5281 Senior's Gun
来源:互联网 发布:淘宝店加权重有哪些 编辑:程序博客网 时间:2024/05/17 07:25
Senior's Gun
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1346 Accepted Submission(s): 476
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
Source
BestCoder Round #47 ($)
///大二贪心第一题
贪心思想,没想到直接开数组,用sort排序竟然能水过。
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<ctype.h>
#include<stdlib.h>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<iomanip>
#include<numeric>
#include <istream> //基本输入流
#include <ostream> //基本输出流
#include <sstream> //基于字符串的流
#include <utility> //STL 通用模板类
#include <complex.h> //复数处理
#include <fenv.h> //浮点环境
#include <inttypes.h> //整数格式转换
#include <stdbool.h> //布尔环境
#include <stdint.h> //整型环境
#include <tgmath.h> //通用类型数学宏
#define L(a,b,c) for(int a = b;a >= c;a --)
#define M(a,b,c) for(int a = b;a < c;a ++)
#define N(a,b) memset(a,b,sizeof(a));
const int MAX=100000000;
const int MIN=-MAX;
typedef long long LL;
typedef int T;
typedef double D;
typedef char C;
using namespace std;
T n,m,a[100010],b[100010];
int cmp(int x,int y)
{
return x>y;
}
int main()
{
T t;
scanf("%d",&t);
while(t--)
{
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
cin>>n>>m;
M(i,0,n)
scanf("%d",&a[i]);
sort(a,a+n,cmp); ///对a数组从大到小排序,
M(i,0,m)
scanf("%d",&b[i]);
sort(b,b+m);
LL sum=0;
M(i,0,n) ///由题意可以看出来,n的值一定小于等于m,所以只需要对a数组进行讨论
{
///贪心思想
if(a[i]>b[i]&&i<m)
sum+=(LL)(a[i]-b[i]);
}
printf("%lld\n",sum);
}
return 0;
}
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<ctype.h>
#include<stdlib.h>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<iomanip>
#include<numeric>
#include <istream> //基本输入流
#include <ostream> //基本输出流
#include <sstream> //基于字符串的流
#include <utility> //STL 通用模板类
#include <complex.h> //复数处理
#include <fenv.h> //浮点环境
#include <inttypes.h> //整数格式转换
#include <stdbool.h> //布尔环境
#include <stdint.h> //整型环境
#include <tgmath.h> //通用类型数学宏
#define L(a,b,c) for(int a = b;a >= c;a --)
#define M(a,b,c) for(int a = b;a < c;a ++)
#define N(a,b) memset(a,b,sizeof(a));
const int MAX=100000000;
const int MIN=-MAX;
typedef long long LL;
typedef int T;
typedef double D;
typedef char C;
using namespace std;
T n,m,a[100010],b[100010];
int cmp(int x,int y)
{
return x>y;
}
int main()
{
T t;
scanf("%d",&t);
while(t--)
{
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
cin>>n>>m;
M(i,0,n)
scanf("%d",&a[i]);
sort(a,a+n,cmp); ///对a数组从大到小排序,
M(i,0,m)
scanf("%d",&b[i]);
sort(b,b+m);
LL sum=0;
M(i,0,n) ///由题意可以看出来,n的值一定小于等于m,所以只需要对a数组进行讨论
{
///贪心思想
if(a[i]>b[i]&&i<m)
sum+=(LL)(a[i]-b[i]);
}
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 Senior's Gun——BestCoder Round #47(贪心)
- HDU 5281 BestCoder Round #47 1002:Senior's Gun
- hdu 5281 Senior's Gun(贪心)(思维)
- 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
- 第三周项目(8):顺序表应用(2)
- .a 静态库
- SDUTOJ3309----乱七八糟的图
- poj 1330
- 命令支持管道
- HDU——5281 Senior's Gun
- 多线程篇 概念混淆面试常考问题
- Android SharedPreferences在不同应用模块里通信
- HDU 1527 取石子游戏(威佐夫博弈)
- 串口mcu:重新编写的ldisc
- ubunt 下搭建ftp服务器
- H5学习之旅-H5列表(8)
- CentOS7安装.tar.gz包
- iOS开发-获取设备电量