A:开场懵逼。然后发现有人1min过,于是就sort了一下,于是就过了。正经证明的话,考虑回文串两端点一定是相同的,所以最多有Σcnti*(cnti+1)/2个,cnti为第i种字母出现次数。而sort是可以达到这个最大值的。

#include<iostream> 
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
int read()
{
    int x=0,f=1;char c=getchar();
    while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
    while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
    return x*f;
}
#define N 100010
int n;
char s[N];
int main()
{
    n=read();
    scanf("%s",s+1);sort(s+1,s+n+1);
    printf("%s",s+1);
    return 0;
}
View Code

相关文章: