zoukankan      html  css  js  c++  java
  • POJ3264 Balanced Lineup

    • 题目大意:Framer John有一段木板,想用以建筑围墙,没有锯子的他仅仅好向Framer Don求助。FD提出要求,FJ每截开一段木板,就要给这段木板长度的钱。FJ想使花费最少,向你求助。

    • 思路:绝对是合并果子的翻版!

      把截木板当成合并木板即可了。

      小心L、n的范围,终于的ans用int装是装不下的。要用long long。

    • 代码例如以下:

    #include<iostream>
    #include<cstdio>
    #include<queue>
    using namespace std;
    int n;
    priority_queue<long long> q;
    
    void init()
    {
        scanf("%d",&n);
        int tmp;
        for (int i=1;i<=n;++i)
        {
            scanf("%d",&tmp);
            q.push(-tmp);
        }
    }
    
    void work()
    {
        int ans=0;
        while (!q.empty())
        {
            int a=q.top();
            q.pop();
            if (q.empty())
            {
                printf("%lld",-ans);
                return;
            }
            int b=q.top();
            q.pop();
            ans+=(a+b);
            q.push(a+b);
        }
    }
    
    int main()
    {
        init();
        work();
        return 0;
    }
  • 相关阅读:
    20210524
    20210521
    20210520
    20210519
    20210518
    20210517
    字符设备驱动三
    字符设备驱动二
    字符设备驱动一
    git基本操作
  • 原文地址:https://www.cnblogs.com/blfbuaa/p/7102642.html
Copyright © 2011-2022 走看看