zoukankan      html  css  js  c++  java
  • HDU 5281 Senior's Gun (贪心)

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

    贪心题目,但是看看我的博客里边相关贪心的题解实在是少的可怜,这里就写出来供大家一起探讨。

    题意还是比较好理解的,这里有一个小小的坑点:枪的数量,和怪物的数量,不一定是相等的,所以我们这里要特殊处理一下。

    reverse函数:http://blog.sina.com.cn/s/blog_6d79d83a0100wh95.html

     1 #include <stdio.h>
     2 #include <string.h>
     3 #include <math.h>
     4 #include <algorithm>
     5 #include <iostream>
     6 #include <ctype.h>
     7 #include <iomanip>
     8 #include <queue>
     9 #include <stdlib.h>
    10 using namespace std;
    11  
    12 int a1[100010],a2[100010];
    13 
    14 int main()
    15 {
    16     int t;
    17     scanf("%d",&t);
    18     while(t--){
    19         int n,m;
    20         scanf("%d %d",&n,&m);
    21         for(int i=0; i<n; i++){
    22             scanf("%d",&a1[i]);
    23         }
    24         for(int i=0; i<m; i++){
    25             scanf("%d",&a2[i]);
    26         }
    27 
    28         sort(a1,a1+n);
    29         reverse(a1,a1+n);
    30         sort(a2,a2+m);
    31 
    32         long long sum=0;
    33         int min1=min(n,m);
    34         for(int i=0; i<min1; i++){
    35             if(a1[i]>a2[i]){
    36                 sum+=a1[i]-a2[i];
    37             }
    38         }
    39         printf("%lld
    ",sum);
    40     }
    41 }
  • 相关阅读:
    Execution Contexts (执行上下文)
    OOP—ECMAScript实现详解
    requireJS入门
    SqlServer 傲娇的表变量
    CSharp进阶 引用类型引发的血案
    CSharp进阶 都是请求惹的祸
    z-index问题
    js中事件(自定义事件)
    做了个后末日朋克风的梦
    昨晚的梦
  • 原文地址:https://www.cnblogs.com/wangmengmeng/p/5226937.html
Copyright © 2011-2022 走看看