codeforce 600C - Make Palindrome
练习string
最小变换次数下,且字典序最小输出回文串。
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include<deque>
#include<vector>
using namespace std;
const double eps = 1e-;
const double PI = acos(-1.0);
const int maxn=;
string st;
int cnt[maxn];
deque<char> qu;
vector<int> odd; int main()
{
cin>>st;
memset(cnt,,sizeof(cnt[]));
for(int i=; i<st.size(); i++)
{
cnt[st[i]]++;
}
for(int i='a'; i<='z'; i++)
{
if(cnt[i]%)
odd.push_back(i);
}
sort(odd.begin(),odd.end());
int l=;
int r=odd.size()-;
while(l<r)
{
cnt[odd[l]]++;
cnt[odd[r]]--;
l++;
r--;
}
for(int i='a'; i<='z'; i++)
{
if(cnt[i]%)
{
cnt[i]--;
qu.push_back(i);
break;
}
}
for(int i='z'; i>='a'; i--)
{
while(cnt[i])
{
qu.push_back(i);
qu.push_front(i);
cnt[i]-=;
}
}
while(qu.size())
{
cout<<qu.front();
qu.pop_front();
}
cout<<endl;
return ;
}
codeforce 600C - Make Palindrome的更多相关文章
- CodeForces - 600C Make Palindrome 贪心
A string is called palindrome if it reads the same from left to right and from right to left. For ex ...
- codeforces 600C Make Palindrome
要保证变化次数最少就是出现次数为奇数的相互转化,而且对应字母只改变一次.保证字典序小就是字典序大的字母变成字典序小的字母. 长度n为偶数时候,次数为奇数的有偶数个,按照上面说的搞就好了. n为奇数时, ...
- Educational Codeforces Round 2
600A - Extract Numbers 20171106 字符串处理题,稍微注意点细节就能水过 #include<stdlib.h> #include<stdio.h&g ...
- Make Palindrome CodeForces - 600C(思维)
A string is called palindrome if it reads the same from left to right and from right to left. For ex ...
- 【Codeforces 600C】Make Palindrome
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 计算出来每个字母出现的次数. 把字典序大的奇数出现次数的字母换成字典序小的奇数出现次数的字母贪心即可. 注意只有一个字母的情况 然后贪心地把字 ...
- PALIN - The Next Palindrome 对称的数
A positive integer is called a palindrome if its representation in the decimal system is the same wh ...
- [LeetCode] Longest Palindrome 最长回文串
Given a string which consists of lowercase or uppercase letters, find the length of the longest pali ...
- [LeetCode] Palindrome Pairs 回文对
Given a list of unique words. Find all pairs of distinct indices (i, j) in the given list, so that t ...
- [LeetCode] Palindrome Permutation II 回文全排列之二
Given a string s, return all the palindromic permutations (without duplicates) of it. Return an empt ...
随机推荐
- Creating a new Signiant Transfer Engine because the previous transfer had to be canceled.
From: http://stackoverflow.com/questions/10548196/application-loader-new-weird-warning-about-signian ...
- HDU 1203 I NEED A OFFER!(01 背包DP)
点我看题目 题意 : 中文题不详述. 思路 :类似于01背包的DP,就是放与不放的问题,不过这个要求概率,至少得到一份offer的反面就是一份也得不到,所以先求一份也得不到的概率,用1减掉就可以得到所 ...
- 学习记录:浏览器JAVASCRIPT里的WINDOWS,DOCUMNET
看完以下这段话之后,就理解DOCUMNET.READY之类的说法了. 或是JAVASCRIPT的浏览器里更细致的操作DOCUMENT的东西了. DOCUMNET和WINDOWS谁大谁小, 立即执行的匿 ...
- flash 动画数据导出 到 coco2d-js ,cocos2d-x 问题的记录
1:必须搞清flash坐标系 和 cocos2d 的坐标系的差异2:对于cocos2d系列坐标系的深入理解: 以前我们常认为 coco2d-x的X,Y是相对坐标系,相对于父节点的X,Y的坐标,这种说法 ...
- java:比较对象
对象内容相等条件:1.对象类型相同(可用instanceof操作符比较)2.对象的成员变量的值完全相同 instanceof 判断对象类型 //a是否为Child对象类型 boolean b = a ...
- js动态创建及移除div的方法
本文实例讲述了js动态创建及移除div的方法.分享给大家供大家参考.具体实现方法如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 ...
- python numpy笔记:给matlab使用者
利用Numpy,python可以进行有效的科学计算.本文给过去常用matlab,现在正学习Numpy的人. 在进行矩阵运算等操作时,使用array还是matrix?? 简短的回答,更多的时候使用arr ...
- C++重载输入和输出操作符以及IO标准库中的刷新输入缓冲区残留字符问题
今天在做C++ Primer习题的14.11时,印象中应该挺简单的一题,结果却费了很长时间. 类定义: typedef string Date; class CheckoutRecord{ publi ...
- Linux内核与根文件系统的关系1
Linux内核与根文件系统的关系开篇题外话:对于Linux初学者来说,这是一个很纠结的问题,但这也是一个很关键的问题!一语破天机: “尽管内核是 Linux 的核心,但文件却是用户与操作系统交互所采用 ...
- C++ 空类默认产生成员函数
class Empty { Empty(){...} //默认构造函数 ~Empty(){...} //默认析构函数 Empty(const Empty&){...} //拷贝构造函数 Emp ...