hdu 5281 Senior's Gun

题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=5281

Senior‘s Gun

Description

Xuejiejie is a beautiful and charming sharpshooter.

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]\leq 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.

Input

In the first line there is an integer $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\leq n, m\leq 100000$, $-10^9 \leq a[i], b[j]\leq 10^9$。

Output

For each test case, output one integer which means the maximum of the bonus Xuejiejie could gain.

Sample Input

1
2 2
2 3
2 2

Sample Output

1

贪心,贪心。。

 1 #include<algorithm>
 2 #include<iostream>
 3 #include<cstdlib>
 4 #include<cstring>
 5 #include<cstdio>
 6 #include<vector>
 7 #include<map>
 8 using std::cin;
 9 using std::cout;
10 using std::endl;
11 using std::find;
12 using std::sort;
13 using std::map;
14 using std::pair;
15 using std::vector;
16 using std::multimap;
17 #define pb(e) push_back(e)
18 #define sz(c) (int)(c).size()
19 #define mp(a, b) make_pair(a, b)
20 #define all(c) (c).begin(), (c).end()
21 #define iter(c) decltype((c).begin())
22 #define cls(arr,val) memset(arr,val,sizeof(arr))
23 #define cpresent(c, e) (find(all(c), (e)) != (c).end())
24 #define rep(i, n) for (int i = 0; i < (int)(n); i++)
25 #define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
26 const int N = 100010;
27 typedef long long ll;
28 int A[N], B[N];
29 int main() {
30 #ifdef LOCAL
31     freopen("in.txt", "r", stdin);
32     freopen("out.txt", "w+", stdout);
33 #endif
34     ll ans;
35     int t, n, m, k, p;
36     scanf("%d", &t);
37     while (t--) {
38         ans = 0;
39         scanf("%d %d", &n, &m);
40         rep(i, n) scanf("%d", &A[i]);
41         rep(i, m) scanf("%d", &B[i]);
42         sort(A, A + n), sort(B, B + m);
43         k = n - 1, p = 0;
44         while (k > -1 && p < m && A[k] > B[p]) ans += A[k--] - B[p++];
45         printf("%lld\n", ans);
46     }
47     return 0;
48 }

hdu 5281 Senior's Gun

时间: 2024-10-16 12:29:47

hdu 5281 Senior's Gun的相关文章

HDU 5281 Senior&#39;s Gun 杀怪

题意:给出n把枪和m个怪.每把枪有一个攻击力,每个怪有一个防御力.如果某把枪的攻击力不小于某个怪的防御力则能将怪秒杀,否则无法杀死.一把枪最多只能杀一个怪,不能用多把枪杀同一个怪.每杀一次怪可以得到枪的攻击力减去怪的防御力的的分数.求得分的最大值. 贪心.首先我们考虑这样一种情况:用攻击力为A的枪杀防御力为a的怪,攻击力为B的枪杀防御力为b的怪.则得分为A - a + B - b. 不妨设A ≤ B,则有a ≤ A ≤ B,b ≤ B.如果有A < b,那么我们考虑用B杀a,而不使用A枪也不杀b

HDU 5281 Senior&amp;#39;s Gun 杀怪

题意:给出n把枪和m个怪.每把枪有一个攻击力,每一个怪有一个防御力.假设某把枪的攻击力不小于某个怪的防御力则能将怪秒杀,否则无法杀死.一把枪最多仅仅能杀一个怪,不能用多把枪杀同一个怪.每杀一次怪能够得到枪的攻击力减去怪的防御力的的分数. 求得分的最大值. 贪心.首先我们考虑这样一种情况:用攻击力为A的枪杀防御力为a的怪,攻击力为B的枪杀防御力为b的怪.则得分为A - a + B - b. 最好还是设A ≤ B,则有a ≤ A ≤ B.b ≤ B.假设有A < b,那么我们考虑用B杀a.而不使用A

HDU 5281 BestCoder Round #47 1002:Senior&#39;s Gun

Senior's Gun Accepts: 235 Submissions: 977 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) 问题描述 学姐姐是一个酷酷的枪手. 她常常会随身携带n把枪,每把枪有一个攻击力a[i]. 有一天她遇到了m只怪兽,每只怪兽有一个防御力b[j].现在她决定用手中的枪消灭这些怪兽. 学姐姐可以用第i把枪消灭第j只怪兽当且仅当b[j]≤a[i],同时她会获

HDU Senior&#39;s Gun (水题)

题意:给n把枪,m个怪兽,每把枪可消灭1怪兽,并获得能量=枪的攻击力-怪兽的防御力.求如何射杀能获得最多能量?(不必杀光) 思路:用最大攻击力的枪杀防御力最小的怪兽明显可获得最大能量.如果每把枪都去射杀刚好1点能量都拿不到的怪物,那简直等于把枪全丢掉. 1 //#pragma comment(linker,"/STACK:102400000,102400000") 2 #include <iostream> 3 #include <stdio.h> 4 #inc

hdu 5280 Senior&#39;s Array

题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5280 Senior's Array Description One day, Xuejiejie gets an array $A$. Among all non-empty intervals of $A$, she wants to find the most beautiful one. She defines the beauty as the sum of the interval. Th

HDU #5283 Senior&#39;s Fish

题目描述: 平面上有一些鱼,初始时鱼会在一些位置,某些时刻编号在一段区间内的鱼会同时向x轴正方向,或y轴正方向平移一定距离,某些时刻会询问一个矩形内鱼的数量. 解题思路: 显然地,求一个矩形内的鱼可以用矩形四个顶点为右上角的整个左下矩形加加减减.那么问题就转化为一个顶点左下角矩形内鱼的数量.注意到鱼只会向右和向上的话,那就很好做.维护两颗线段树,分别维护编号在l~r的鱼的x坐标最大值.y坐标最大值.每次修改对应区间加.每次如果区间最大值大于限制,那就找出最大值的位置,赋为-inf,同时在树状数组

hdu 5280 Senior&#39;s Array(最大子段和)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5280 题意:将一个长度为n的数组,将里面某一个数改为p,使改变后最大子段和最大. 题解:dp[i]=max(dp[i-1)+a[i],a[i]),表示以第 i 个数结束的最大子段和,时间复杂度为O(n). 1)由于n<=1000,可以暴力解决,将每一个数都依次改为p,求出最大的子段和,再去这些最大子段和中最大的,时间复杂度为O(n*n); #include <iostream> #inclu

HDU 5280 Senior&#39;s Array (暴力,水)

题意:给一个数列,再给一个数字p,要求p一定要替换掉数列中的一个元素,然后求最大连续子序列之和. 思路:1000*1000的复杂度,O(n*n) .就是每个都试,然后求和. 1 #include <bits/stdc++.h> 2 #define LL long long 3 #define pii pair<int,int> 4 #define INF 0x7f7f7f7f 5 using namespace std; 6 const int N=2000; 7 int a[N]

[最大子序列和]Hdu 5280 Senior&#39;s Array

题意:一个序列,在其中一个数必须替换成给定数字p的条件下,求最大连续子序列之和. 依次把每一个数替换成p,求每次的最大连续和,找出最大值.O(n^2). #include <cstdio> #include <iostream> #include <cstring> #include <algorithm> typedef long long ll; using namespace std; const int MAXN=1000+5; const int