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;
    }
    
    
  • 相关阅读:
    Entity Framework在WCF中序列化的问题
    OTS
    ClickHouse原理解析与应用实践--摘录
    在docker中安装ogg19
    性能测试指标记录
    docker安装oracle12c记录
    docker安装oracle19c记录
    kudu
    stm32模拟iic从机程序
    STM32启动代码注释
  • 原文地址:https://www.cnblogs.com/AWCXV/p/8191196.html
Copyright © 2011-2022 走看看