分割木板的顺序是自由的,所以每次选择两块最短的板,组合在一起,增加队列,原来两个板出队,直到队列中为空或者仅仅剩下一个板时结束。这里使用优先队列较为方便。

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<algorithm>
  5. #include<queue>
  6. #define ll __int64
  7. using namespace std;
  8.  
  9. int len[20005];
  10.  
  11. int main()
  12. {
  13. //freopen("d:\\test.txt","r",stdin);
  14. int n;
  15. ll ans=0;
  16. cin>>n;
  17. priority_queue<int,vector<int>,greater<int> >q;//最小元素在队头
  18. for(int i=0;i<n;i++)
  19. {
  20. cin>>len[i];
  21. q.push(len[i]);
  22. }
  23. while(!q.empty())
  24. {
  25. int t1=q.top();
  26. q.pop();
  27. if(!q.empty())
  28. {
  29. int t2=q.top();
  30. q.pop();
  31. ans+=t1+t2;
  32. q.push(t1+t2);
  33. }
  34. else break;
  35. }
  36. printf("%I64d\n",ans);
  37. return 0;
  38. }

POJ3253 Fence Repair(贪心)的更多相关文章

  1. POJ 3253 Fence Repair 贪心 优先级队列

    Fence Repair Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 77001   Accepted: 25185 De ...

  2. POJ 3253 Fence Repair (贪心)

    Fence Repair Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit ...

  3. 优先队列 poj3253 Fence Repair

    Fence Repair Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 51411   Accepted: 16879 De ...

  4. Poj3253 Fence Repair (优先队列)

    Fence Repair Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 67319   Accepted: 22142 De ...

  5. poj-3253 fence repair(贪心题)

    题目描述: Farmer John wants to repair a small length of the fence around the pasture. He measures the fe ...

  6. poj3253 Fence Repair(贪心+哈夫曼 经典)

    https://vjudge.net/problem/POJ-3253 很经典的题,运用哈夫曼思想,想想很有道理!! 具体实现还是有点绕人,最后被long long卡了一下,看数据大小的时候单纯相乘了 ...

  7. POJ3253 Fence Repair【贪心】

    我们的小伙伴Bingo真的很调皮,他在上课的路上看到树上有个鸟窝,他就想去把他捅下来,但是鸟窝很高他够不到,于是他就到处找木棍,想把这些木棍接在一起,然后去捅鸟窝.他一共找了N跟木棍 (1 ≤ N ≤ ...

  8. poj3253 Fence Repair

    http://poj.org/problem?id=3253 Farmer John wants to repair a small length of the fence around the pa ...

  9. poj3253 Fence Repair【哈夫曼树+优先队列】

    Description Farmer John wants to repair a small length of the fence around the pasture. He measures ...

随机推荐

  1. android客户端从服务器端获取json数据并解析的实现代码(重要)

    首先客户端从服务器端获取json数据 1.利用HttpUrlConnection /** * 从指定的URL中获取数组 * @param urlPath * @return * @throws Exc ...

  2. 【HDU 4463 Outlets】最小生成树(prim,kruscal都可)

    以(x,y)坐标的形式给出n个点,修建若干条路使得所有点连通(其中有两个给出的特殊点必须相邻),求所有路的总长度的最小值. 因对所修的路的形状没有限制,所以可看成带权无向完全图,边权值为两点间距离.因 ...

  3. thecorner.com.cn - Customer Care

    thecorner.com.cn - Customer Care 所有主题 帮助 关于我们 thecorner.com 是通过专业的"迷你商店"形式荟萃最新男士.女士精选时尚商品和 ...

  4. 源码推荐(7.17):不规则按钮类似于遥控器按钮,一个可以最大程度简化PageView与TabView切换的第三方框架

    不规则按钮,类似于遥控器按钮,可以单独控制按钮的上下左右(作者:masa_chu) 不规则按钮,类似于遥控器按钮,可以单独控制按钮的上下左右 测试环境:Xcode 6.2,iOS 6.0以上 Lazy ...

  5. Oracle delete input与delete all input

    oracle官方文档提示:If you had specified DELETE INPUT rather than DELETE ALL INPUT, then RMAN would have on ...

  6. Google Map 根据坐标 获取地址信息

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.X ...

  7. SQL Server 事务嵌套

    示例代码: DECLARE @TranCounter INT; SET @TranCounter = @@TRANCOUNT; -- Procedure called when there is -- ...

  8. windows server 2003进行相邻磁盘扩容(server 2008的直接右键就可以解决)

    vCenter下的win server 2003 的D盘需要扩容,解决办法是,先将D盘由原来的200GB增加到了2TB(win server 2003选择MBR的限制),重启win server 20 ...

  9. Android系统环境变量配置

    ANDROID_HOME D:\Program Files\Android-sdk D:\AndroidSDK\android-sdk ANDROID_SDK_HOME %ANDROID_HOME% ...

  10. WindowsForm 记事本 对话框

    textbox:     属性:         text:文本         selectedtext:获取或设置选中文本         canundo:是否能够撤销     方法:       ...