• 运输


    题目描述

    现在商品都已经装好了。搬家公司的老板Mr.B先生走了过来。他告诉我们今天是他的生日,他特别高兴。本来决定免费运输的,但是因为某些因素他改变了主意。现在已知N件商品,和搬运它们其中每一件的费用。现在Mr.B决定让我们每次任意选取2件商品。将这两件商品合并成一件新的商品,其搬运费用是将选出的2个商品的费用之和除以K的运算结果。(K由文件读入)如此反复,直到只收一件商品的钱,这个就是商店要付的费用。掌柜的想尽可能的少付钱,以便将更多的钱捐给希望工程。所以请你帮他计算一下最少只用付多少钱。

    输入

    n,k

    w1,w2,…,wn(每一件商品的搬运费用)

    输出

    输出一个数字,表示最少付多少钱。

    样例输入

    5 2
    1 2 3 4 5
    

    样例输出

    1

    提示

    n<=10000,k<=10000

    代码

    #pragma GCC optimize(1)
    #pragma GCC optimize(2)
    #pragma GCC optimize(3)
    #pragma GCC optimize("Ofast")
    #include<bits/stdc++.h>
    #define rep(i,j,k) for(register int i=(j);i<=(k);++i)
    using namespace std;
    priority_queue < int > s;
    int n, k;
    template<class T> inline void read(T &x) {
        x=0;
        register char c=getchar();
        register bool f=0;
        while(!isdigit(c))f^=c=='-',c=getchar();
        while(isdigit(c))x=x*10+c-'0',c=getchar();
        if(f)x=-x;
    }
    int main() {
        read(n), read(k);
        rep(i, 1, n) {
            register int x;
            read(x);
            s.push(x);
        }
        for (register int i = 1; i < n; i ++) {
            register int x;
            x = s.top();
            s.pop();
            x += s.top();
            s.pop();
            x = x / k;
            s.push(x);
        }
        cout << s.top() << endl;
        return 0;
    }
  • 相关阅读:
    The Problem of Programming Language Concurrency Semantics
    AMD64 Architecture Programmer’s Manual Volume 1: Application Programming
    Intel® 64 Architecture Memory Ordering White Paper
    Systems Benchmarking Crimes
    A Guide to Undefined Behavior in C and C++, Part 1
    39张IoT传感器工作原理GIF动图汇总
    全真互联
    从Context到go设计理念
    中国汽车基础软件发展白皮书3.0
    设备影子
  • 原文地址:https://www.cnblogs.com/LJA001162/p/12678588.html
Copyright © 2020-2023  润新知