CodeForces 600C【构造】
题意:
在原字符串中修改数量最少,然后保证最小字典序。
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=2e5+10;
int a[100];
char s[N];
char ans[N];
int main()
{
scanf("%s",s);
int len=strlen(s);
memset(a,0,sizeof(a));
if(len%2==0)
{
for(int i=0;i<len;i++)
{
int x=s[i]-'a';
a[x]++;
}
for(int i=0;i<26;i++)
{
if(a[i]%2)
{
for(int j=25;j>i;j--)
{
if(a[j]%2)
{
a[j]--;
a[i]++;
break;
}
}
}
}
int s=0;
int t=len-1;
for(int i=0;i<26;i++)
{
if(a[i]&&a[i]%2==0)
{
while(a[i])
{
ans[s++]=i+'a';
ans[t--]=i+'a';
a[i]-=2;
}
}
}
ans[len]='\0';
printf("%s\n",ans);
}
else
{
for(int i=0;i<len;i++)
{
int x=s[i]-'a';
a[x]++;
}
for(int i=0;i<26;i++)
{
if(a[i]%2!=0)
{
for(int j=25;j>i;j--)
{
if(a[j]&&a[j]%2!=0)
{
a[j]--;
a[i]++;
break;
}
}
}
}
int s=0;
int t=len-1;
for(int i=0;i<26;i++)
{
if(a[i]&&a[i]%2==0)
{
while(a[i]>0)
{
a[i]-=2;
ans[s++]=i+'a';
ans[t--]=i+'a';
}
}
if(a[i]&&a[i]%2!=0)
{
while(a[i]>1)
{
a[i]-=2;
ans[s++]=i+'a';
ans[t--]=i+'a';
}
ans[len/2]=i+'a';
}
}
ans[len]='\0';
printf("%s\n",ans);
}
return 0;
}
CodeForces 600C【构造】的更多相关文章
- B - Save the problem! CodeForces - 867B 构造题
B - Save the problem! CodeForces - 867B 这个题目还是很简单的,很明显是一个构造题,但是早训的时候脑子有点糊涂,想到了用1 2 来构造, 但是去算这个数的时候算错 ...
- Johnny Solving CodeForces - 1103C (构造,图论)
大意: 无向图, 无重边自环, 每个点度数>=3, 要求完成下面任意一个任务 找一条结点数不少于n/k的简单路径 找k个简单环, 每个环结点数小于n/k, 且不为3的倍数, 且每个环有一个特殊点 ...
- Codeforces 746G(构造)
G. ...
- Codeforces 1188A 构造
题意:给你一颗树,树的边权都是偶数,并且边权各不相同.你可以选择树的两个叶子结点,并且把两个叶子结点之间的路径加上一个值(可以为负数),问是否可以通过这种操作构造出这颗树?如果可以,输出构造方案.初始 ...
- C - Long Beautiful Integer codeforces 1269C 构造
题解: 这里的m一定是等于n的,n为数最大为n个9,这n个9一定满足条件,根据题目意思,前k个一定是和原序列前k个相等,因此如果说我们构造出来的大于等于原序列,直接输出就可以了,否则,由于后m-k个一 ...
- Dividing the numbers CodeForces - 899C (构造)
大意: 求将[1,n]划分成两个集合, 且两集合的和的差尽量小. 和/2为偶数最小差一定为0, 和/2为奇数一定为1. 显然可以通过某个前缀和删去一个数得到. #include <iostrea ...
- 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 772C 构造 数学 + dp + exgcd
首先我们能注意到两个数x, y (0 < x , y < m) 乘以倍数互相可达当且仅当gcd(x, m) == gcd(y, m) 然后我们可以发现我们让gcd(x, m)从1开始出发走 ...
- Jzzhu and Apples CodeForces - 449C (构造,数学)
大意: 求从[1,n]范围选择尽量多的数对, 使得每对数的gcd>1 考虑所有除2以外且不超过n/2的素数p, 若p倍数可以选择的有偶数个, 直接全部划分即可 有奇数个的话, 余下一个2*p不划 ...
随机推荐
- Cena使用
打开cena,在工具-选项中,修改G++和GCC的编译命令.格式:[g++目录]g++.exe %s.cpp -o %s.exe [编译选项]例如以下命令使用刚安装的mingw4.8.1 g++编译, ...
- 【BZOJ3505】[Cqoi2014]数三角形 组合数
[BZOJ3505][Cqoi2014]数三角形 Description 给定一个nxm的网格,请计算三点都在格点上的三角形共有多少个.下图为4x4的网格上的一个三角形. 注意三角形的三点不能共线. ...
- svn提交异常file is scheduled for addition, but is missing
svn提交错误file is scheduled for addition, but is missing svn ci -m "" svn: E155010: Commit fa ...
- Automating hybrid apps
Automating hybrid apps One of the core principles of Appium is that you shouldn’t have to change you ...
- appium(9)-uiautomator UiSelector
uiautomator UiSelector Appium enables searching using UiSelectors. UiScrollable is also supported.// ...
- c# 获取当前行的位置信息
StackTrace st = new StackTrace(new StackFrame(true)); StackFrame sf = st.GetFrame(0); //文件位置 Console ...
- @SuppressWarnings("serial")注解
@SuppressWarnings J2SE 提供的一个批注或者注解.该批注的作用是给编译器一条指令,告诉它对被批注的代码元素内部的某些警告保持静默,即忽略这些警告信息. 在平常的编码过程中,我们经常 ...
- 写给精明Java开发者的测试技巧
我们都会为我们的代码编写测试,不是吗?毫无疑问,我知道这个问题的答案可能会从 “当然,但你知道怎样才能避免写测试吗?” 到 “必须的!我爱测试”都有.接下来我会给你几个小建议,它们可以让你编写测试变得 ...
- TP框架中的多种方法代码(C,G,L,T,I,N,D,M,A,R,B,U,W,S,F,E)
C方法 function C($name=null, $value=null,$default=null) { static $_config = array(); // 无参数时获取所有 if (e ...
- APTM敏捷性能测试模型
随着应用系统的日趋复杂,仅在系统测试和验收测试阶段执行性能测试已经不能满足迟早发现和解决系统性能瓶颈的要求,Connie Smith博士和Lloyd Winlliams博士在他们提出 的软件性能工程( ...