HDU 5281 bestcoder Round #47 1002:senior ' s Gun

Source: Internet
Author: User

Senior ' s Gunaccepts:235submissions:977Time limit:2000/1000 MS (java/others)Memory limit:65536/65536 K (java/others) Problem description
Learning your sister is a cool shooter. She always carries it with her.
    
        n   
  
 
    
 Put the gun, every gun has a damage
    
        a[i]    
  
 
    
 。 One day, she met
    
        m   
  
 
    
 Monsters, every beast has a defensive power.
    
        b[J]    
  
 
    
 。 Now she decided to use her gun to kill the monsters. Learn to use the first sister
    
        i   
  
 
    
 Kill the gun.
    
        J   
  
 
    
 Only monsters when and only if
   
    
        b[J]≤a[i] 
 

    
   , and she will get
   
    
        a[i]? b [J]  
 

    
   The score. Each gun can be used at most once, and the beast will not revive after death. Now, my sister wants to know how many points she can get (she doesn't have to kill all the monsters).
Enter a description
The first line contains an integer
    
       T    
  
 
    
 That represents the number of test data groups. For each set of test data: The first row contains two integers
    
        n,m    
  
 
    
 , indicating the number of guns and the number of monsters. The second line contains
    
        n   
  
 
    
 An integer
    
        a[i]    
  
 
    
 , which indicates the weapon's attack. The third line contains
    
        m   
  
 
    
 An integer
    
        b[J]    
  
 
    
 , which represents the defense of monsters.
    
        1≤n,m≤100000   
  
 
    
 ,
   
    ?  ten  9 ≤a[I],b[J]≤  ten  9 
   。
Output description
For each set of test data, output an integer representing the corresponding answer.
Input sample
12 22 32 2
Output sample
1

The last AC when my heart is extremely collapsed, but also because some small details missed their first time in the week of AC two problems, this time if the AC two questions to explain themselves this period has been some progress, but the method is not wrong AH light speed of the boy why not self-confidence to check the details Ah, At that time the last 15 minutes, oneself completely disorderly, in thinking method what is wrong, in fact careful observation data will find that ans must exceed ah, int changed long long ah.

Find out if it's really the right game to exercise your ability to think, even if it's a small game. Keep your head down. The speed of light kid, CMP is also wrong, the key is also added two sort inside, you then the head is how chaotic you tell me ...

This problem is greedy, with the most ruthless weapon to pick the most soft persimmon pinch ah, nothing to say. The whole greed once again, on AC ... It's so simple ... Do not always think of the second question how hard it is ....

Code:

#include <iostream> #include <string> #include <cstring> #include <algorithm> #include < Cmath>using namespace Std;int a[100005];int b[100005];bool cmp (int a,int b) {  return a>b;} int main () {    int Test;    int gun_num,guai,i,j;long long ans;    cin>>test;        while (test--)    {        ans=0;        cin>>gun_num>>guai;        for (i=1;i<=gun_num;i++)            cin>>a[i];        for (i=1;i<=guai;i++)            cin>>b[i];        Sort (a+1,a+gun_num+1,cmp);        Sort (b+1,b+guai+1);                I=1;j=1;        while (I<=gun_num&&j<=guai)        {            if (a[i]-b[j]>0)                ans + = a[i]-b[j];            i++;            j + +;        }        cout<<ans<<endl;    }    return 0;}



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

HDU 5281 bestcoder Round #47 1002:senior ' s Gun

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.