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;
    }
    
    
  • 相关阅读:
    mysql性能优化
    pymysql模块
    mysql数据表约束
    MySQL数据库
    IO模型
    8451
    8946531
    6783
    256213
    27822
  • 原文地址:https://www.cnblogs.com/AWCXV/p/8191196.html
Copyright © 2011-2022 走看看