• hdu6168 Numbers 多校赛


    将b数组排序,取出最小的两项作为

             a1,a2

    删除

           a1,a2,a1+a2

    再取出最小项作为

              a3​​

    再删除

          a3​​,a1​​+a3​​,a2​​+a3​​

    再取出最小项作为

              a4

    依次列推

    思路很清楚,就是实现方式,下面这种是别人博客园里我觉得比较简洁清晰的一种,学习了。

     1 #include<cstdio>
     2 #include<cstdlib>
     3 #include<cstring>
     4 #include<string>
     5 #include<algorithm>
     6 #include<iostream>
     7 #include<queue>
     8 #include<map>
     9 #include<cmath>
    10 #include<set>
    11 #include<stack>
    12 
    13 using namespace std;
    14 
    15 vector<int>ve;
    16 multiset<int>ss;
    17 int m;
    18 
    19 int main()
    20 {
    21     cin.sync_with_stdio(false);
    22     while(cin>>m)
    23     {
    24         ve.clear();
    25         ss.clear();
    26         int a;
    27         for(int i = 0; i < m; i++)
    28         {
    29             cin>>a;
    30             ss.insert(a);
    31         }
    32         
    33         while(ss.size()>0)
    34         {
    35             int u = *ss.begin();
    36             ss.erase(ss.lower_bound(u));
    37             for(int i = 0; i < ve.size(); i++)
    38             {
    39                 ss.erase(ss.lower_bound(u+ve[i]));
    40             }
    41             ve.push_back(u);
    42         }
    43         
    44         cout<<ve.size()<<endl;
    45         cout<<ve[0];
    46         for(int i = 1; i < ve.size(); i++)
    47             cout<<' '<<ve[i];
    48         cout<<endl;
    49     }
    50     
    51     return 0;
    52 }
  • 相关阅读:
    addEventListener事件委托
    ES6的解构赋值
    JavaScript 中最​​重要的保留字
    HTML 5 Web 存储
    Node.js 里的 process.nextTick(),简单理解
    实现多层DIV叠加的js事件穿透
    touch事件中的touches、targetTouches和changedTouches详解
    Promise.all( ) 的使用
    js 中的五种迭代方法
    迭代
  • 原文地址:https://www.cnblogs.com/Xycdada/p/7413336.html
Copyright © 2020-2023  润新知