zoukankan      html  css  js  c++  java
  • HDU-5281

    Senior's Gun

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 842    Accepted Submission(s): 309


    Problem 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]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 nm.

    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.

    1n,m100000109a[i],b[j]109
     
    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
     
    Source
    /**
        题意:xuejiejie有n把枪,每把枪的威慑力是mmap[i],现在有m个master,每个master
              的攻击性是temp[i] ,现在xuejiejie得到的bonus值为mmap[i] - temp[i] 
              现在要求bonus的值最大化
        做法:暴力
    **/
    #include <iostream>
    #include <stdio.h>
    #include <string.h>
    #include <algorithm>
    using namespace std;
    #define maxn 100000 + 10
    #define INF 0x7fffffff
    long long  mmap[maxn];
    long long  temp[maxn];
    int main()
    {
    //#ifndef ONLINE_JUDGE
    //    freopen("in.txt","r",stdin);
    //#endif // ONLINE_JUDGE
        int T;
        scanf("%d",&T);
        while(T--)
        {
            int n,m;
            scanf("%d %d",&n,&m);
            for(int i=0;i<n;i++)
            {
                scanf("%lld",&mmap[i]);
            }
            for(int i=0;i<m;i++)
            {
                scanf("%lld",&temp[i]);
            }
            sort(mmap,mmap+n);
            sort(temp,temp+m);
            long long sum = 0;
            long long ans = 0;
            int p = 0;
            for(int i=n-1;i>=0;i--)
            {
                if(p>=m) break;
                if(mmap[i] >= temp[p])
                {
                   ans += mmap[i] - temp[p];
                   sum = max(sum,ans);
                   p++;
                }
                else
                {
                    p++;
                    i++;
                }
            }
            printf("%lld
    ",sum);
        }
        return 0;
    }
  • 相关阅读:
    大数据,TB、PB、EB
    localhost,127.0.0.1,本机IP,三者的区别
    git rollback commands
    世界会给这样静等花开的人足够的回报
    柳传志:一个人越是成功,所遭受的委屈也越多!
    大型网站架构之分布式消息队列
    设置 php 上传文件大小
    简单php post请求
    linux下mysql 备份、还原数据库
    Windows下 Apache xdebug
  • 原文地址:https://www.cnblogs.com/chenyang920/p/4644020.html
Copyright © 2011-2022 走看看