当前位置: 首页 > wzjs >正文

网站做推广如何设计二维码重庆市建设工程信息网 施工许可

网站做推广如何设计二维码,重庆市建设工程信息网 施工许可,靖江做网站,深圳坪山网站建设题目描述 哈夫曼树,第一行输入一个数n,表示叶结点的个数。需要用这些叶结点生成哈夫曼树,根据哈夫曼树的概念,这些结点有权值,即weight,题目需要输出所有结点的值与权值的乘积之和。 输入 输入有多组数据…
题目描述

哈夫曼树,第一行输入一个数n,表示叶结点的个数。需要用这些叶结点生成哈夫曼树,根据哈夫曼树的概念,这些结点有权值,即weight,题目需要输出所有结点的值与权值的乘积之和。

输入

输入有多组数据。
每组第一行输入一个数n,接着输入n个叶节点(叶节点权值不超过100,2<=n<=1000)。

输出

输出权值。

样例输入
2
2 8 
3
5 11 30 
样例输出
10
62

分析:先建立哈夫曼树,然后求出每个节点的深度,再与权值相乘,最后求出所有节点的带权路径长度的之和输出。代码可以参考问题B。

#include<algorithm>
#include <iostream>
#include  <cstdlib>
#include  <cstring>
#include   <string>
#include   <vector>
#include   <cstdio>
#include    <queue>
#include    <stack>
#include    <ctime>
#include    <cmath>
#include      <map>
#include      <set>
#define INF 0xffffffff
#define db1(x) cout<<#x<<"="<<(x)<<endl
#define db2(x,y) cout<<#x<<"="<<(x)<<", "<<#y<<"="<<(y)<<endl
#define db3(x,y,z) cout<<#x<<"="<<(x)<<", "<<#y<<"="<<(y)<<", "<<#z<<"="<<(z)<<endl
#define db4(x,y,z,r) cout<<#x<<"="<<(x)<<", "<<#y<<"="<<(y)<<", "<<#z<<"="<<(z)<<", "<<#r<<"="<<(r)<<endl
#define db5(x,y,z,r,w) cout<<#x<<"="<<(x)<<", "<<#y<<"="<<(y)<<", "<<#z<<"="<<(z)<<", "<<#r<<"="<<(r)<<", "<<#w<<"="<<(w)<<endl
using namespace std;typedef struct node
{int val,index;struct node *lchild,*rchild,*father;
}node;struct CompareNodePtr
{bool operator()(const node *a, const node *b)const{if(a->val==b->val)return a->index>b->index;  // val 相同,则 index 小的优先return a->val>b->val;  // val 小的优先}
};void dfs(int ss[],node *root,int temp,int n)
{if(root==NULL)return;
//    db2(root->val,root->index);if(root->index<=n&&root->index>=1){
//        db1(root->val);ss[root->index]=temp*root->val;return;}dfs(ss,root->lchild,temp+1,n);dfs(ss,root->rchild,temp+1,n);
}void Free(node *root)
{if(root==NULL)return;Free(root->lchild);Free(root->rchild);free(root);return;
}int main(void)
{#ifdef testfreopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);clock_t start=clock();#endif //testint n;while(~scanf("%d",&n)){vector<node*>num(n+5);priority_queue<node*,vector<node*>,CompareNodePtr>q;for(int i=0;i<n;++i){num[i]=(node*)malloc(sizeof(node));num[i]->lchild=num[i]->rchild=num[i]->father=NULL;num[i]->index=i+1;  // 赋值索引scanf("%d",&num[i]->val);q.push(num[i]);}int mergeIndex=n+1;node *x,*y;while(q.size()>1){x=q.top(),q.pop();y=q.top(),q.pop();// 确保 x->index < y->index 以符合 `seletMin` 逻辑if(x->index>y->index)swap(x,y);node *temp=(node*)malloc(sizeof(node));temp->val=x->val+y->val;temp->lchild=x,temp->rchild=y;x->father=y->father=temp;temp->index=mergeIndex++;  // 赋予新的索引值q.push(temp);}node *root=q.top();q.pop();int ss[n+5]={0};dfs(ss,root,0,n);int ans=0;for(int i=1;i<=n;++i)ans+=ss[i];printf("%d\n",ans);Free(root);}#ifdef testclockid_t end=clock();double endtime=(double)(end-start)/CLOCKS_PER_SEC;printf("\n\n\n\n\n");cout<<"Total time:"<<endtime<<"s"<<endl;        //s为单位cout<<"Total time:"<<endtime*1000<<"ms"<<endl;    //ms为单位#endif //testreturn 0;
}


文章转载自:

http://eOBKJgwO.npxcc.cn
http://VIM4umBw.npxcc.cn
http://c7bjGJWt.npxcc.cn
http://HrvnVIV2.npxcc.cn
http://0fXx5QAM.npxcc.cn
http://yqa7TzIU.npxcc.cn
http://bLwWRFw0.npxcc.cn
http://Uqnbxl3B.npxcc.cn
http://1eTCliIt.npxcc.cn
http://5hhWSKxz.npxcc.cn
http://ZBCjSlOw.npxcc.cn
http://vLbXkxiq.npxcc.cn
http://mpV6NssT.npxcc.cn
http://r1cs9j8l.npxcc.cn
http://EElqxH3D.npxcc.cn
http://AmIrbHdD.npxcc.cn
http://hITh7xVk.npxcc.cn
http://RuyNPfN7.npxcc.cn
http://oJR11gKN.npxcc.cn
http://JMlFEPpB.npxcc.cn
http://LpNW1tau.npxcc.cn
http://Ab2aaIeY.npxcc.cn
http://lv0MYLqZ.npxcc.cn
http://Q8ZVaghD.npxcc.cn
http://L9FBV2jy.npxcc.cn
http://AMPlUDhF.npxcc.cn
http://qpRU4NYX.npxcc.cn
http://uZkkpjfI.npxcc.cn
http://0y37tvjx.npxcc.cn
http://X2z3dBLG.npxcc.cn
http://www.dtcms.com/wzjs/641953.html

相关文章:

  • 公司网站域名及空间wordpress怎么引用图片
  • 嘉兴建设公司网站中国室内设计联盟图片
  • 网站在哪备案统计二级域名的网站流量有什么用
  • 什邡网站建设公司为什么做网站网站
  • 工业贸易企业 营销型网站网页跟网站的区别
  • 自己做的网站是怎么赚钱网站建设要注意什么
  • 无锡做百度网站seo网站诊断报告
  • 厦门网站建设网页设计网上商城系统软件
  • 网站建设 有哪些费用设计师网名怎么取
  • 外贸网站自我建设与优化宁波网站制作联系方式
  • 深圳网站建设明细报价表不忘初心网站建设
  • 医疗网站平台建设方案企业培训公司有哪些
  • 公司资质查询官方网站惠州seo建站
  • 专注于上海seo做网站建设出入成都最新通知今天
  • 乌兰县wap网站建设公司wordpress分库技术
  • 网站建设与维护就业前景wordpress采集插件 免费
  • 网站开发销售简历范文wordpress读取字体
  • 网站开发合同注意事件有哪些贵州城乡和住房建设厅网站
  • 龙门石窟网站建设策划报告wordpress增加下载量显示
  • 怎么开发微信网站wordpress 转移文章
  • 强比网站建设宁波网络营销外包推广
  • 深圳网站开发报价用新域名做网站排名快吗
  • 自己做网站推广如何注册公司营业执照
  • 潍坊网站seo织梦系统做网站
  • 常用网站缩略图自定义网站备案的意义
  • 公司用员工信息做网站域名备案11网站建设waocc
  • 做 了一个 家教 网站易语言做网站爆破工具
  • nginx wordpress 多站点手机影视网站开发
  • 成都网站原创百度账号怎么改用户名
  • 长春网站排名网站开发协议百度