• POJ 3253


      题目链接:http://poj.org/problem?id=3253

      非常简单的一道数据结构的题目哈,好久没刷过题了,现在再也不会刷那些很难的题目了,刷题只是为了让我保持清醒-.-

      思路就是Huffman编码的简单应用~,一开始输出没用long long,导致WA了一发

      其次是复习了一下STL里 priority_queue的使用姿势~

    /*************************************************************************
        > File Name: 3253.cpp
        > Author: jusonalien
        > Mail: jusonalien@qq.com
        > Created Time: 2015年02月11日 星期三 23时34分22秒
     ************************************************************************/
    
    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <queue>
    using namespace std;
    
    int main() {
            
        priority_queue<int,vector<int>,greater<int> > q;
        int n;
        while(~scanf("%d",&n)) {
            while(!q.empty()) q.pop();
            long long  ans = 0;
            int ele;
            while(n--) {
                scanf("%d",&ele);
                q.push(ele);
            }
            while(!q.empty()) {
                int d = q.top();
                ans += q.top();
                q.pop();
                if(q.empty()) break;
                d += q.top();
                ans += q.top();
                q.pop();
                if(q.empty()) break;
                q.push(d);
            }
            printf("%lld
    ",ans);
        }
        return 0;
    }
  • 相关阅读:
    10_树基础部分
    11_多线程
    14_JUC
    Servlet代码实例
    关于JSP引用资源路径
    Struts2代码实例
    hadoop三大核心组件介绍
    presto自定义函数开发
    git使用
    hive优化总结
  • 原文地址:https://www.cnblogs.com/jusonalien/p/4287195.html
Copyright © 2020-2023  润新知