hdu 5281 Senior's Gun

简介:

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5281

题目大意:学姐姐是一个酷酷的枪手。

她常常会随身携带n 把枪,每把枪有一个攻击力a[i] 。

有一天她遇到了m 只怪兽,每只怪兽有一个防御力b[j] 。现在她决定用手中的枪消灭这些怪兽。

学姐姐可以用第i 把枪消灭第j 只怪兽当且仅当b[j]≤a[i] ,同时她会获得a[i]−b[j] 的分数。

每把枪至多只能使用一次,怪兽死后也不会复活。现在学姐姐想知道她最多能得到多少分(她可以不用消灭所有的怪兽)。
解题思路:把a[i]从大到小排一下序,把b[i]从小到大排一下序,然后比较一下就行了

#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
const int maxn=100000+5;
typedef long long LL;
LL a[maxn],b[maxn];
bool cmp(LL a, LL b)
{
    return a>b;
}
int main()
{
    int T;
    scanf("%d",&T);
    int m,n;
    while(T--)
    {
        scanf("%d%d",&m,&n);
        for(int i=0; i<m; i++)
            scanf("%lld",&a[i]);
        sort(a,a+m,cmp);
        for(int i=0; i<n; i++)
            scanf("%lld",&b[i]);
        sort(b,b+n);
        //int minn=n<m?n:m;
        int minn=min(m,n);
        LL sum=0;
        for(int i=0; i<minn; i++)
        {
            if(a[i]>=b[i])
                sum+=a[i]-b[i];
            else
                break;
        }
        printf("%lld\n",sum);
    }
    return 0;
}
目录
相关文章
UVA10474 大理石在哪儿 Where is the Marble?
UVA10474 大理石在哪儿 Where is the Marble?
ZOJ - Summer 2018 - Contest 2 by Astolfo - Problems - 1002: Hazard and The Triangle
ZOJ - Summer 2018 - Contest 2 by Astolfo - Problems - 1002: Hazard and The Triangle
106 0
ZOJ - Summer 2018 - Contest 2 by Astolfo - Problems - 1002: Hazard and The Triangle
|
测试技术
HDU-1847,Good Luck in CET-4 Everybody!(巴什博弈)
HDU-1847,Good Luck in CET-4 Everybody!(巴什博弈)
ZOJ - Summer 2018 - Contest 1 by SBconscious - Problems - 1001: Saber
ZOJ - Summer 2018 - Contest 1 by SBconscious - Problems - 1001: Saber
94 0
|
人工智能 Java C++
UVA - 10474 Where is the Marble
Raju and Meena love to play with Marbles. They have got a lot of marbles with numbers written on them.
1417 0