Codeforces Round #516 Div. 2 C. Oh Those Palindromes

题目链接:https://codeforces.com/contest/1064/problem/C

 

题意:

给你一个长度为n的由小写字母组成的字符串,让你对它进行重新排列,使得它的回文子串是最多的。

 

思路:

对样例进行操作发现,当把所有的相同的字母放在一起的时候回文子串就是最多的,因为这个时候每个字母都可以产生尽可能多的贡献。比如样例1,排列成oooll时回文子串最多。

 

代码:

#define push_back pb
#define make_pair mk
#define rd read()
#define mem(a,b) memset(a,b,sizeof(a))
#define bug printf("*********\n");
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define FIN freopen(D://code//in.txt", "r", stdin);
#define debug(x) cout<<"["<<x<<"]" <<endl;
#define IO ios::sync_with_stdio(false),cin.tie(0);
#pragma comment(linker,"/STACk:1024000000,1024000000")
//#include<bits/stdc++.h>
#include<time.h>
#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<cmath>
#include<map>
#include<algorithm>
#include<string>
#include<string.h>
#include<set>
#include<queue>
#include<stack>
#include<functional>
using std::pair;


typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
//const double PI=acos(-1);


const int maxn = 1e5 + 10;
const int maxm = 2e3 + 10;
const int mod = 1000000007;
const int inf = 0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
const double dinf=1e20;
const double eps=1e-8;
using namespace std;

ll read() {
    ll X = 0, p = 1; char c = getchar();
    for(; c > '9' || c < '0'; c = getchar()) if(c == '-') p = -1;
    for(; c >= '0' && c <= '9'; c = getchar()) X = X * 10 + c - '0';
    return X * p;
}
int sgn(double x)
{
    if(fabs(x)<eps) return 0;
    if(x<0) return -1;
    return 1;
}
//*************************************************************
int main()
{
    int n;
    string s;
    cin>>n>>s;
    int num[30];
    mem(num,0);
    for(int i=0;i<n;i++)
    {
        num[s[i]-'a']++;
    }
    for(int i=0;i<26;i++)
    {
       // cout<<num[i]<<endl;
        for(int j=0;j<num[i];j++)
        {
            cout<<char(i+'a');
        }
    }
    cout<<endl;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值