嘟嘟嘟

只要将每一种字母放一块输出就行了。

证明1:比如 1 2 3 4 5 6,那么这个序列对答案的贡献分别是1和5,2和4 ,3和6……如果重新排列成x x x x o o,会发现对          x x o x x o  答案的贡献不变,所以得证。

证明2:字母ai有xi个,那么对答案的最大贡献为xi * (xi - 1) / 2,重排后能达到理论上界,所以为最优解。   

 #include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<vector>
#include<stack>
#include<queue>
using namespace std;
#define enter puts("")
#define space putchar(' ')
#define Mem(a, x) memset(a, x, sizeof(a))
#define rg register
typedef long long ll;
typedef double db;
const int INF = 0x3f3f3f3f;
const db eps = 1e-;
const int maxn = 1e5 + ;
inline ll read()
{
ll ans = ;
char ch = getchar(), last = ' ';
while(!isdigit(ch)) last = ch, ch = getchar();
while(isdigit(ch)) ans = (ans << ) + (ans << ) + ch - '', ch = getchar();
if(last == '-') ans = -ans;
return ans;
}
inline void write(ll x)
{
if(x < ) x = -x, putchar('-');
if(x >= ) write(x / );
putchar(x % + '');
} int n, a[];
char c[maxn]; int main()
{
n = read(); scanf("%s", c);
for(int i = ; i < n; ++i) a[c[i] - 'a']++;
for(int i = ; i <= ; ++i)
if(a[i]) while(a[i]--) putchar(i + 'a');
enter;
return ;
}

最新文章

  1. 从webRoot中下载Excel
  2. python进阶学习笔记(四)--多线程thread
  3. SQL2005中设置自动编号字段【转】
  4. POJ3280(DP)
  5. 史上比较用心的纯代码实现 AutoLayout
  6. APM代码学习笔记3:执行过程
  7. [译]Java设计模式之解释器
  8. MySQL 权限与用户表
  9. SpriteKit中的共享动作(Sharing Actions)
  10. Python中4位1进制数与float浮点数互相转换
  11. Ajax发送请求等待时弹出模态框等待提示
  12. python - one day
  13. WordConut
  14. day 08 函数
  15. mybatis---属性和字段映射
  16. Cpu表现出正弦曲线
  17. 纯css实现不固定行数的文本在一个容器内垂直居中
  18. Python 标准库之 xml.etree.ElementTree
  19. ZOJ 3279-Ants(线段树)
  20. mac下使用github 上传代码

热门文章

  1. 一:Nginx知识整理
  2. 二:SpringAOP
  3. 流畅的python和cookbook学习笔记(五)
  4. JavaScript之如何对客户端进行检测
  5. jquery+springMVC实现文件上传
  6. 读EntityFramework.DynamicFilters源码_心得_示例演示02
  7. centos自带python2.6无法使用pip命令
  8. ThreadLocal 理解
  9. IDEA 自动生成serialVersionUID
  10. 视差滚动-background-attachement