版本比较
题解:B2168 哈夫曼编码
正文
增加 5 行删除 5 行
15 行未改动16171819202122232425262710 行未改动3839404142434445464748495015 行未改动struct note{int x, y;bool operator < (note _) const{return x > _.x;}};priority_queue <note> q;void dfs(int x, string s){ans[x] = s;if(!l[x]) return ;10 行未改动}k = n;while(1){x = q.top().x, y = q.top().y, q.pop();if(q.empty()) break;xx = q.top().x, yy = q.top().y, q.pop();q.push({x + xx, ++k}), l[k] = y, r[k] = yy;}dfs(k, "");for(int i = 1; i <= n; i++) cout << s[i] << " " << ans[i] << "\n";return 0;}```15 行未改动16171819202122232425262710 行未改动3839404142434445464748495015 行未改动struct note{int x, y;bool operator < (note _) const{return x > _.x;}};priority_queue <note> q;void dfs(int x, string s){ans[x] = s;if(!l[x]) return ;10 行未改动}k = n;while(1){x = q.top().x, y = q.top().y, q.pop();if(q.empty()) break;xx = q.top().x, yy = q.top().y, q.pop();q.push({x + xx, ++k}), l[k] = y, r[k] = yy;}dfs(k, "");for(int i = 1; i <= n; i++) cout << s[i] << " " << ans[i] << "\n";return 0;}```