HDU 5281 Senior ' s Gun kill monster

Source: Internet
Author: User

Test instructions: Give the n gun and M a strange. Each gun has a single attack, each with a defensive force. If a gun's attack is not less than a certain strange defensive force can kill the strange second, or can not be killed. A gun can only kill a strange, can not use more than shoot the same strange. Every time you kill a monster, you get the weapon's attack minus the odd defensive score. The maximum number of points to be evaluated.






Greedy. First of all, we consider a situation: with the attack of a shot defense force is a strange, the attack of B shot Defense Force is a B's strange. The score is A-a + b-b.

If you wish to set A≤b, there is a≤a≤b,b≤b. If there is a < B, then we consider using B to kill a, and do not use a gun does not kill B, then get divided into b-a, and the original score compared to the B points, less a points, because a is smaller than B, so this way of killing strange obviously scored more. That is to say, for some two killed a certain two strange, if the attack of the lower damage than the defense of the higher than the strange, then would prefer to use the high-attack gun to kill the lower defense of the strange, do not use the low-attack gun does not kill the higher defense of the strange. So, for a viable kill scheme, if you want to score the most, then you must have the attack of any one of the used guns is not less than any one killed the strange defensive force. That is, all the guns and all the blame, the random use of which shot which strange is the same. In this case, you can first on the gun and strange respectively according to the attack power increment and the defense Force to increase the order, and then use the maximum attack value of the shooting defense value of the smallest strange, the second largest shooting defense Force value of the second big Strange, and so on, until the kill can not blame, the score is the maximum value.






#include <iostream> #include <cstdio> #include <cmath> #include <cstring> #include <string > #include <algorithm> #include <stack> #include <queue> #include <vector> #include <map > #include <set>using namespace std;const int MAX = 100005;int N, m;__int64 A[max], b[max];void input () {    scanf ("%d%d", &n, &m);    for (int i = 0; i < n; i++)        scanf ("%i64d", &a[i]);    for (int i = 0; i < m; i++)        scanf ("%i64d", &b[i]);} void Solve () {    sort (a, a + N);    Sort (b, B + m);    __int64 ans = 0;    int i = n-1, j = 0;    while (i >= 0 && J < m && A[i] > b[j])        ans + = a[i--]-b[j++];    printf ("%i64d\n", ans);} int main () {    int T;    scanf ("%d", &t);    while (t--)    {        input ();        Solve ();    }    return 0;}



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

HDU 5281 Senior ' s Gun kill monster

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.