zoukankan      html  css  js  c++  java
  • A

    Score : 200 points

    Problem Statement

    Snuke is having a barbeque party.

    At the party, he will make N servings of Skewer Meal.

    Example of a serving of Skewer Meal

    He has a stock of 2N skewers, all of which will be used in Skewer Meal. The length of the i-th skewer is Li. Also, he has an infinite supply of ingredients.

    To make a serving of Skewer Meal, he picks 2 skewers and threads ingredients onto those skewers. Let the length of the shorter skewer be x, then the serving can hold the maximum of x ingredients.

    What is the maximum total number of ingredients that his N servings of Skewer Meal can hold, if he uses the skewers optimally?

    Constraints

    • 1≦N≦100
    • 1≦Li≦100
    • For each iLi is an integer.

    Input

    The input is given from Standard Input in the following format:

    N
    L1 L2  L2N
    

    Output

    Print the maximum total number of ingredients that Snuke's N servings of Skewer Meal can hold.


    Sample Input 1

    2
    1 3 1 2
    

    Sample Output 1

    3
    

    If he makes a serving using the first and third skewers, and another using the second and fourth skewers, each serving will hold 1 and 2 ingredients, for the total of3.


    Sample Input 2

    5
    100 1 2 3 14 15 58 58 58 29
    

    Sample Output 2

    135

    挺有意思的题目,排个序就ok了

    /* ***********************************************
    Author        :guanjun
    Created Time  :2016/7/16 23:23:01
    File Name     :agc1a.cpp
    ************************************************ */
    #include <iostream>
    #include <cstring>
    #include <cstdlib>
    #include <stdio.h>
    #include <algorithm>
    #include <vector>
    #include <queue>
    #include <set>
    #include <map>
    #include <string>
    #include <math.h>
    #include <stdlib.h>
    #include <iomanip>
    #include <list>
    #include <deque>
    #include <stack>
    #define ull unsigned long long
    #define ll long long
    #define mod 90001
    #define INF 0x3f3f3f3f
    #define maxn 10010
    #define cle(a) memset(a,0,sizeof(a))
    const ull inf = 1LL << 61;
    const double eps=1e-5;
    using namespace std;
    priority_queue<int,vector<int>,greater<int> >pq;
    struct Node{
        int x,y;
    };
    struct cmp{
        bool operator()(Node a,Node b){
            if(a.x==b.x) return a.y> b.y;
            return a.x>b.x;
        }
    };
    
    bool cmp(int a,int b){
        return a>b;
    }
    int a[300];
    int main()
    {
        #ifndef ONLINE_JUDGE
        //freopen("in.txt","r",stdin);
        #endif
        //freopen("out.txt","w",stdout);
        int n;
        while(cin>>n){
            for(int i=1;i<=n*2;i++)cin>>a[i];
            sort(a+1,a+1+2*n);
            int sum=0;
            for(int i=2*n;i>=1;i-=2){
                sum+=a[i-1];
            }
            cout<<sum<<endl;
        }
        return 0;
    }

     

  • 相关阅读:
    springboot 整合 pagehelper
    Linux maven安装
    linux 查看端口状态
    mysql执行顺序
    Java int/int 保留2位小数
    【每日一题】30.储物点的距离 (区间处理,前缀和/线段树//树状数组)
    【每日一题】29.maze (BFS 进阶)
    2016年第七届 蓝桥杯C组 C/C++决赛题解
    2016年第七届 蓝桥杯A组 C/C++决赛题解
    第六届蓝桥杯C++A组 A~F题题解
  • 原文地址:https://www.cnblogs.com/pk28/p/5677533.html
Copyright © 2011-2022 走看看