题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1053
#include
#include
#include
#include
using namespace std;
struct node
{
int key;
int f;
int lson,rson;
bool operator < (const node x)const
{
return x.key<key;
}
};
node father;
node g[3100];
int sum=0;
void fuc(node x,int cnt);
int main()
{
char str[1100];
while(scanf("%s",str)!=EOF)
{
sum=0;
priority_queue p;
int len=strlen(str);
if(len==3&&str[0]=='E'&&str[1]=='N'&&str[2]=='D')
{
break;
}
int ii=0;
for(int i=0;i
{
int cnt=1;
char c;
if(str[i]!='#')
{
c=str[i];
str[i]='#';
for(int j=i+1;j
{
if(str[j]==c)
{
cnt++;
str[j]='#';
}
}
g[ii].f=ii;
g[ii].lson=g[ii].rson=-1;
g[ii].key=cnt;
p.push(g[ii]);
ii++;
}
}
if(ii==1)
{
printf("%d %d 8.0\n",8*len,len);
}
else
{
while(p.size()!=1)
{
node tmp1,tmp2;
tmp1=p.top();
p.pop();
tmp2=p.top();
p.pop();
g[ii].f=ii;
g[ii].lson=tmp1.f;
g[ii].rson=tmp2.f;
tmp1.f=ii;
tmp2.f=ii;
g[ii].key=tmp1.key+tmp2.key;
p.push(g[ii]);
ii++;
}
father=p.top();
p.pop();
fuc(father,0);
printf("%d %d %.1lf\n",len*8,sum,(double)(len*8)/sum);
}
}
return 0;
}
void fuc(node x,int cnt)
{
if(x.lson==-1&&x.rson==-1)
{
sum+=x.key*cnt;
return ;
}
fuc(g[x.lson],cnt+1);
fuc(g[x.rson],cnt+1);
}
#include
#include
#include
#include
using namespace std;
struct node
{
};
node father;
node g[3100];
int sum=0;
void fuc(node x,int cnt);
int main()
{
}
void fuc(node x,int cnt)
{
}