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 ...
随机推荐
- [转载]ASP.NET MVC URL重写与优化(进阶篇)-继承RouteBase玩转URL
引言-- 在初级篇中,我们介绍了如何利用基于ASP.NET MVC的Web程序中的Global文件来简单的重写路由.也介绍了它本身的局限性-依赖于路由信息中的键值对: 如果键值对中没有的值,我们无法将 ...
- 团体程序设计天梯赛-练习集L1-018. 大笨钟
L1-018. 大笨钟 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 微博上有个自称“大笨钟V”的家伙,每天敲钟催促码农们爱惜 ...
- install Nagios on Unbuntu Unix
Ubuntu Quickstart Up To: ContentsSee Also: Quickstart Installation Guides, Security Considerations I ...
- 【BZOJ 2453|bzoj 2120】 2453: 维护队列 (分块+二分)
2453: 维护队列 Description 你小时候玩过弹珠吗? 小朋友A有一些弹珠,A喜欢把它们排成队列,从左到右编号为1到N.为了整个队列鲜艳美观,小朋友想知道某一段连续弹珠中,不同颜色的弹珠有 ...
- findBugs学习小结
原文地址:http://www.cnblogs.com/doit8791/archive/2012/10/22/2734730.html 今天代码质量再次强调java代码提交SVN前要经过findBu ...
- java版AC自动机
class Trie { int [][]Next=new int[500005][128]; int []fail=new int[500005]; int []end=new int[500005 ...
- java:I/O 往原文件追加内容
原来txt内容: "我要添加内容" import java.io.*; class Test { public static void main(String[] args) { ...
- 最短路径算法之三——Bellman-Ford算法
Bellman-Ford算法 Dijkstra算法无法判断含负权边的图的最短路. 如果遇到负权,在没有负权回路存在时,即便有负权的边,也可以采用Bellman-Ford算法正确求出最短路径. PS:负 ...
- 【HDOJ】4412 Sky Soldiers
1. 题目描述有$k$个伞兵跳伞,有$m$个汇点.当伞兵着陆后,需要走向离他最近的汇点.如何选择这$m$个结点,可以使得士兵最终行走的距离的期望最小.求这个最小的期望. 2. 基本思路假设已经选好了这 ...
- 几种java通信(rmi,http,hessian,webservice)协议性能比较
一.综述 本文比较了RMI,Hessian,Burlap,Httpinvoker,web service等5种通讯协议的在不同的数据结构和不同数据量时的传输性能.RMI是java语言本身提供的通讯协议 ...