1736. 扑克游戏 (Standard IO)

Time Limits: 1000 ms Memory Limits: 128000 KB

Description

  有一棵无穷大的满二叉树,根为star,其余所有点的权值为点到根的距离,如图:

  

  现在你有一些扑克牌,点数从1到13,你要把这些扑克牌全部放到这个树上:

  1. 当你把点数为i的扑克牌放在权值为j的点上,那么你会得到i*j的分数。

  2. 当你把一个扑克牌放在一个节点上,那么你就不能把别的扑克牌放在这个节点以及这个节点的子树上。

  你的目标是最小化你的得分。

Input

  文件名为 poker.in

  输入第一行为一个数字N,表示你有的扑克牌数;

  接下来一行N个数字,数字在1到13之间。

Output

  文件名为 poker.out

  一个数字,最小得分。

Sample Input

3

5 10 13

Sample Output

43

Data Constraint

Hint

【样例说明】

  

【数据范围】

  30%数据 N<=100

  100%数据满足1<=N<=10000.

题解

这是今天做的第四道哈夫曼树专题了

总结一下

解法大同小异,只是换个方式问而已

类似这道题,题目说得分是 i * j 其实就是哈夫曼树,模型转换一下就好了

代码

#include<iostream>
#include<iostream>
#include<cstdio>
#define INF 2147483647
#define N 20000
using namespace std; long long dui[N*2+1],top;
void add(long x)
{ long now;
dui[++top]=x;
for(now=top;dui[now/2]>dui[now]&&now>1;now/=2)
swap(dui[now],dui[now/2]);
}
long qu()
{ long ans=dui[1],now;
bool t=false;
dui[1]=INF;
now=1;
while(!t){
t=true;
if(now*2==top||dui[now*2]<dui[now*2+1]){
if(dui[now]>dui[now*2]){
swap(dui[now],dui[now*2]);
now=now*2;
t=false;
}
}else if(now*2+1<=top)
if(dui[now]>dui[now*2+1]){
swap(dui[now],dui[now*2+1]);
now=now*2+1;
t=false;
}
}
return ans;
} int main()
{ long n,m,i,q;
long long ans=0;
scanf("%ld",&n);
for(i=1;i<=n;i++){
scanf("%ld",&q);
add(q);
}
for(i=1;i<n;i++){
q=qu()+qu();
ans+=q;
add(q);
}
printf("%lld\n",ans);
return 0;
}

ps:

看过我其他博文的有没有感觉代码很熟悉

没错,就是合并果子

JZOJ 1736. 扑克游戏 (Standard IO)的更多相关文章

  1. JZOJ 1349. 最大公约数 (Standard IO)

    1349. 最大公约数 (Standard IO) Time Limits: 1000 ms Memory Limits: 65536 KB Description 小菜的妹妹小诗就要读小学了!正所谓 ...

  2. JZOJ 1776. 经济编码 (Standard IO)

    1776. 经济编码 (Standard IO) Time Limits: 1000 ms Memory Limits: 128000 KB Description 为降低资料储存的空间或增加资料传送 ...

  3. JZOJ 1774. 合并果子 (Standard IO)

    1774. 合并果子 (Standard IO) Time Limits: 1000 ms Memory Limits: 65536 KB Description 在一个果园里,多多已经将所有的果子打 ...

  4. 1003. 猜数游戏 (Standard IO)

    题目描述 有一个“就是它”的猜数游戏,步骤如下:请你对任意输入的一个三位数x,在这三位数后重复一遍,得到一个六位数,467-->467467.把这个数连续除以7.11.13,输出最后的商. 输入 ...

  5. JZOJ 2137. 【GDKOI2004】城市统计 (Standard IO)

    2137. [GDKOI2004]城市统计 (Standard IO) Time Limits: 1000 ms  Memory Limits: 128000 KB  Detailed Limits  ...

  6. JZOJ 5326. LCA 的统计 (Standard IO)

    5326. LCA 的统计 (Standard IO) Time Limits: 1000 ms Memory Limits: 131072 KB Description Input Output S ...

  7. JZOJ 5307. 【NOIP2017提高A组模拟8.18】偷窃 (Standard IO)

    5307. [NOIP2017提高A组模拟8.18]偷窃 (Standard IO) Time Limits: 1000 ms Memory Limits: 262144 KB Description ...

  8. JZOJ 5286. 【NOIP2017提高A组模拟8.16】花花的森林 (Standard IO)

    5286. [NOIP2017提高A组模拟8.16]花花的森林 (Standard IO) Time Limits: 1000 ms Memory Limits: 131072 KB Descript ...

  9. JZOJ 5305. 【NOIP2017提高A组模拟8.18】C (Standard IO)

    5305. [NOIP2017提高A组模拟8.18]C (Standard IO) Time Limits: 1000 ms Memory Limits: 131072 KB Description ...

随机推荐

  1. rest framework-restful介绍-长期维护

    ###############   django框架-rest framework    ############### # django rest framework 框架 # 为什么学习这个res ...

  2. EncryptUtils

    package me.zhengjie.core.utils; import org.springframework.util.DigestUtils; import javax.crypto.Cip ...

  3. 手撸XGBoost流程(未完成)

    网上的一篇文章,讲的挺清楚的. XGBoost原理分析及实践 XGBoost的原理 xgboost原理--刘建平博客 要注意的地方: 1.预测值y(pred)和损失函数L(y,y(hat))中的y(h ...

  4. spring boot 配置文件properties和YAML详解

    spring boot 配置文件properties和YAML详解 properties中配置信息并获取值. 1:在application.properties配置文件中添加: 根据提示创建直接创建. ...

  5. django框架进阶-中间件-长期维护

    ##################    为什么使用中间件?      ####################### 先说几个需求, 1,url的白名单,url=[ "XX"] ...

  6. The Mean of the Sample Mean|Standard Deviation of the Sample Mean|SE

    7.2  The Mean and Standard Deviation of the Sample Mean Recall that the mean of a variable is denote ...

  7. python函数参数理解

    1.位置参数 函数调用时,参数赋值按照位置顺序依次赋值. e.g. def function(x): 3 return x * x 5 print function(2) 输出结果: 4 def fu ...

  8. vyos的Xvlan配置方式

    set interfaces bridge br0 address '172.12.12.10/24' //开启一个桥借口,用于xvlan的通信 set interfaces vxlan vxlan0 ...

  9. notepad++下载及安装

    下载notepad++: 官网 安装:https://jingyan.baidu.com/article/154b463109921828cb8f4151.html 如果下载的64位没有插件管理器,单 ...

  10. js实现数组去重怎么实现?

    方法1. 创建一个新的临时数组来保存数组中已有的元素 var a = new Array(1,2,2,2,2,5,3,2,9,5,6,3); Array.prototype.unique1 = fun ...