当前位置: 代码迷 >> 综合 >> hdu 1053
  详细解决方案

hdu 1053

热度:20   发布时间:2023-11-24 14:39:51.0

题目  :Problem - 1053 (hdu.edu.cn)

#include<bits/stdc++.h>
using namespace std;
string str;
int num[30];
int bfs(){int a,b,sum=0;priority_queue<int,vector<int>,greater<int> >q;for(int i=0;i<=26;i++){if(num[i]){q.push(num[i]);}}if(q.size()==1){sum=q.top();}while(q.size()>1){a=q.top();q.pop();b=q.top();q.pop();sum+=a+b;q.push(a+b);}return sum;
} 
int main(){while(cin>>str){if(str=="END"){break;}memset(num,0,sizeof num);int len=str.size();for(int i=0;i<len;i++){if(str[i]=='_'){num[26]++;}else{num[str[i]-'A']++;}}int res=bfs();printf("%d %d %.1f\n",len*8,res,len*8*1.0/res);}return 0;
}