zoukankan      html  css  js  c++  java
  • 【例题 8-11 UVA-10954】Add All

    【链接】 我是链接,点我呀:)
    【题意】

    在这里输入题意

    【题解】

    就是合并果子。。 每次都合并最小的就可以啦。 别忘了初始化

    【代码】

    /*
      	1.Shoud it use long long ?
      	2.Have you ever test several sample(at least therr) yourself?
      	3.Can you promise that the solution is right? At least,the main ideal
      	4.use the puts("") or putchar() or printf and such things?
      	5.init the used array or any value?
      	6.use error MAX_VALUE?
      	7.use scanf instead of cin/cout?
      	8.whatch out the detail input require
    */
    /*
        一定在这里写完思路再敲代码!!!
    */
    #include <bits/stdc++.h>
    #define ll long long
    using namespace std;
    
    int n;
    priority_queue<ll,vector<ll>,greater<ll> > q;
    
    int main(){
    	#ifdef LOCAL_DEFINE
    	    freopen("rush_in.txt", "r", stdin);
    	#endif
    	ios::sync_with_stdio(0),cin.tie(0);
        while (cin >> n &&n){
            while (!q.empty()) q.pop();
            for (int i = 1;i <= n;i++){
                int x;cin >> x;
                q.push(x);
            }
            ll ans = 0;
            for (int i = 1;i <= n-1;i++){
                ll x = q.top();q.pop();
                ll y = q.top();q.pop();
                q.push(x+y);
                ans+=(x+y);
            }
            cout << ans << endl;
        }
    	return 0;
    }
    
    
  • 相关阅读:
    机器学习中的规则化
    TF-IDF 文本相似度分析
    数据分析实践:遇到的问题及感想
    记录工作中用到的linux命令
    回归:预测数值型数据
    FP
    Application
    Mac安装sqlite3
    查看百度CUID方法
    leetcode算法题整理
  • 原文地址:https://www.cnblogs.com/AWCXV/p/8191196.html
Copyright © 2011-2022 走看看