博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CF1063A Oh Those Palindromes
阅读量:4556 次
发布时间:2019-06-08

本文共 1362 字,大约阅读时间需要 4 分钟。

 

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

证明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,重排后能达到理论上界,所以为最优解。   

1 #include
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 #include
10 #include
11 using namespace std;12 #define enter puts("") 13 #define space putchar(' ')14 #define Mem(a, x) memset(a, x, sizeof(a))15 #define rg register16 typedef long long ll;17 typedef double db;18 const int INF = 0x3f3f3f3f;19 const db eps = 1e-8;20 const int maxn = 1e5 + 5;21 inline ll read()22 {23 ll ans = 0;24 char ch = getchar(), last = ' ';25 while(!isdigit(ch)) last = ch, ch = getchar();26 while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();27 if(last == '-') ans = -ans;28 return ans;29 }30 inline void write(ll x)31 {32 if(x < 0) x = -x, putchar('-');33 if(x >= 10) write(x / 10);34 putchar(x % 10 + '0');35 }36 37 int n, a[30];38 char c[maxn];39 40 int main()41 {42 n = read(); scanf("%s", c);43 for(int i = 0; i < n; ++i) a[c[i] - 'a']++;44 for(int i = 0; i <= 26; ++i)45 if(a[i]) while(a[i]--) putchar(i + 'a');46 enter;47 return 0;48 }
View Code

 

转载于:https://www.cnblogs.com/mrclr/p/9895220.html

你可能感兴趣的文章
css nth-child 的应用
查看>>
关于白盒测试
查看>>
MooTools 1.2 Beginner's Guide
查看>>
计算储存、交互和语言
查看>>
bzoj2067: [Poi2004]SZN
查看>>
买彩票中了6500万啊!!!!!
查看>>
php中的curl常用例子
查看>>
ASP.NET MVC 4 异步加载控制器
查看>>
上海悬臂式货架制作材料分析
查看>>
[专题]动态规划的总结和体会
查看>>
css控制显示超出多少行以后开始出现省略号的写法
查看>>
如何将桌面的路径定义到其它盘符,如d:\users\桌面
查看>>
selenium操作(浏览器)
查看>>
学习MongoDB 六: MongoDB查询(游标操作、游标信息)(三)
查看>>
(12)We should aim for perfection — and stop fearing failure
查看>>
ReentrantLock锁 源码分析
查看>>
POJ 3321 DFS序+线段树
查看>>
百度地图之事件处理——获取所在的经纬度(百度地图简单使用)
查看>>
2011的第一场雪
查看>>
Java随机4-Hashset
查看>>