【Codeforces 600C】Make Palindrome
【链接】 我是链接,点我呀:)
【题意】
题意
【题解】
计算出来每个字母出现的次数。
把字典序大的奇数出现次数的字母换成字典序小的奇数出现次数的字母贪心即可。
注意只有一个字母的情况
然后贪心地把字典序小的字母放在前面就好
【代码】
#include <bits/stdc++.h>
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define ll long long
using namespace std;
const int N = 2e5;
string s;
char ans[N+10];
int cnt[30];
int main(){
ios::sync_with_stdio(0),cin.tie(0);
cin >> s;
rep1(i,0,(int)s.size()-1) cnt[s[i]-'a'+1]++;
for (int i = 1;i <= 26;i++)
if (cnt[i]&1){
for (int j = 26;j >= i+1;j--)
if (cnt[j]&1){
cnt[i]++;
cnt[j]--;
break;
}
}
rep1(i,1,(int)s.size()/2){
for (int j = 1;j <= 26;j++){
if ( (cnt[j]>0 && cnt[j]%2==0) || (cnt[j]>2) ){
ans[i] = (char)(j+'a'-1);
ans[(int)s.size()-i+1] = ans[i];
cnt[j]-=2;
break;
}
}
}
if ((int)s.size()%2==1){
for (int j = 1;j <= 26;j++)
if (cnt[j]%2==1)
ans[(int)s.size()/2+1] = (char)(j+'a'-1);
}
for (int i = 1;i <= (int)s.size();i++){
cout<<ans[i];
}
return 0;
}
【Codeforces 600C】Make Palindrome的更多相关文章
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 798A】Mike and palindrome
[题目链接]:http://codeforces.com/contest/798/problem/A [题意] 让你严格改变一个字符,使得改变后的字符串为一个回文串; 让你输出可不可能; [题解] 直 ...
- 【19.77%】【codeforces 570D】Tree Requests
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【34.88%】【codeforces 569C】Primes or Palindromes?
time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【25.64%】【codeforces 570E】Pig and Palindromes
time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【44.19%】【codeforces 608D】Zuma
time limit per test2 seconds memory limit per test512 megabytes inputstandard input outputstandard o ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
随机推荐
- 4. extjs中form中的frame:true表示什么
转自:https://blog.csdn.net/qiu512300471/article/details/23737217 设置为true时可以为panel添加背景色.圆角边框等,如下图 下面的是f ...
- 12. Ext.Ajax 对ajax的支持
转自:http://www.cnblogs.com/lipan/archive/2011/12/09/2272793.html 本篇主要介绍一下ExtJs常用的几个对JS语法的扩展支持,包括Ajax封 ...
- SAP中的货币与金额
- SpringCloud(Finchley版本)中Zull过滤器ResponseBoby返回中文乱码解决方案
Spring Cloud带有"Cloud"的字样,但它并不是云计算解决方案,而是在Spring Boot基础上构建的,用于快速构建分布式系统的通用模式的工具集.使用Spring C ...
- xshell、xftp最新版下载方法
https://www.netsarang.com/download/main.html 登录邮箱打开第一个下载地址进行下载
- Android 性能优化(27)*zipalign让apk数据对齐,运行更快。
1.zipalign 简介 zipalign is an archive alignment tool that provides important optimization to Android ...
- TimeOut Error :因为远程服务器关闭导致mnist数据集不能通过input_data下载下来
解决办法: 修改文件: C:\Users\501-PC\AppData\Local\Programs\Python\Python35\Lib\site-packages\tensorflow\con ...
- MVC之参数验证(二)
MVC内部针对这此验证是如何实现的咧???现在我们就来分析一下这此验证的背后故事.... 1.ModelValidator与ModelValidatorProvider 虽然Model绑定方式的因绑定 ...
- 【Python-2.7】list类型
list是Python中的一种数据类型,也就是"列表".在Python中我们可以对list类型进行插入,删除,修改等操作. ##新建list类型 >>> ball ...
- Ngnix SSL配置(HTTP、HTTPS兼容)
一.使用阿里云提供证书 下载aliyun证书for Nginx,解压出两个文件,.pem和.key文件 在nginx安装目录Conf文件夹下新建cert文件夹,拷贝两个密钥文件 二.配置nginx 打 ...