【BZOJ】1666 [Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏
【算法】贪心&&堆
【题解】反过来看就是合并任意两块木板,花费为木板长度之和。
显然从最小的两块开始合并即可,用堆(优先队列)维护。
经典DP问题石子归并是只能合并相邻两堆石子,所以不能贪心。
手写堆版本见http://www.cnblogs.com/onioncyc/p/6212840.html
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
priority_queue<int,vector<int>,greater<int> >q;
const int maxn=;
int n;
long long ans;
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
{
int u;
scanf("%d",&u);
q.push(u);
}
for(int i=;i<n;i++)
{
int A=q.top();q.pop();
int B=q.top();q.pop();
ans+=A+B;q.push(A+B);
}
printf("%lld",ans);
return ;
}
【BZOJ】1666 [Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏的更多相关文章
- bzoj:1666: [Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏
Description 奶牛们又在玩一种无聊的数字游戏.输得很郁闷的贝茜想请你写个程序来帮她在开局时预测结果.在游戏的开始,每头牛都会得到一个数N(1<=N<=1,000,000).此时奶 ...
- bzoj 1666: [Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏【模拟】
模拟 #include<iostream> #include<cstdio> using namespace std; int n,ans; int main() { scan ...
- BZOJ 1666: [Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏 幼儿园测试题
本来以为是一道数学题,一顿XJBT导式子,结果就是个幼儿园都会的模拟. Code: #include<bits/stdc++.h> #define ll long long using n ...
- 【BZOJ】1666: [Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏(刷水严重)
http://www.lydsy.com/JudgeOnline/problem.php?id=1666 这种我就不说了.. #include <cstdio> #include < ...
- BZOJ1666: [Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏
1666: [Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 5 ...
- BZOJ 1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛( LIS )
裸的LIS ----------------------------------------------------------------- #include<cstdio> #incl ...
- 【BZOJ】3404: [Usaco2009 Open]Cow Digit Game又见数字游戏(博弈论)
http://www.lydsy.com/JudgeOnline/problem.php?id=3404 写挫好几次.... 裸的博弈论即可.. #include <cstdio> #in ...
- bzoj 1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛【dp+树状数组+hash】
最长上升子序列.虽然数据可以直接n方但是另写了个nlogn的 转移:f[i]=max(f[j]+1)(a[j]<a[i]) O(n^2) #include<iostream> #in ...
- BZOJ1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛
1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 665 Solved: 419 ...
随机推荐
- .从列表结束中删除第N个节点
描述 给定一个链表,从列表的最后删除倒数第n个元素 例如: 给定链表:1-> 2-> 3-> 4-> 5,并且n = 2. 删除倒数第二个,链表将变为1-> 2-> ...
- 团队作业7——第二次项目冲刺(Beta版本)-第一篇
1.当天站立式会议照片: 2.工作分工: 团队成员 分工 郭达22120 项目整合,后台代码 刘德培44060 数据库模块后台连接 石浩洋22061 前台界面优化 曾繁钦22056 前台界面优化.测试 ...
- iOS-修改导航栏文字字体和颜色
//修改导航栏文字字体和颜色 nav.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:[RGBColor co ...
- <Effective C++>读书摘要--Implementations<二>
<Item29> Strive for exception-safe code. 1.如下面的代码 class PrettyMenu { public: ... void changeBa ...
- 3dContactPointAnnotationTool开发日志(二三)
smpl模型得是一个整体,于是我让子物体的选项卡的删除按钮消失,这样就不会删除不必要的东西然后产生奇怪现象:
- SpringBoot2.0(一) mybatis
使用mybatis springboot使用mybatis主要依赖 mybatis-spring-boot-starter 来实现.其提供了2中解决方案,一种是使用注解:另一种是简化后的传统的xml方 ...
- nargchk函数 matlab【转】
功能说明 验证输入参数的个数 函数语法 msgstring = nargchk(minargs, maxargs, numargs)msgstring = nargchk(minargs, max ...
- mac终端命令-----常规操作
OSX 的文件系统 OSX 采用的Unix文件系统,所有文件都挂在跟目录 / 下面,所以不在要有Windows 下的盘符概念. 你在桌面上看到的硬盘都挂在 /Volumes 下. 比如接上个叫做 US ...
- Android命名格式化详解
严格换行 一般情况下一个“:”一换行 建议函数的“{}”分别占一行 例:public void ooSomething() { …… } 不要用: 例:public void doSomething ...
- Python 开篇及第一个Python程序
本节内容 python 简单介绍 python 2.x 或者python 3.x python 安装 第一个python程序 一.python简单介绍 python的创始人为吉多.范罗苏姆(Guido ...