codeforces 600C Make Palindrome】的更多相关文章

A string is called palindrome if it reads the same from left to right and from right to left. For example "kazak", "oo", "r" and "mikhailrubinchikkihcniburliahkim" are palindroms, but strings "abb" and &qu…
要保证变化次数最少就是出现次数为奇数的相互转化,而且对应字母只改变一次.保证字典序小就是字典序大的字母变成字典序小的字母. 长度n为偶数时候,次数为奇数的有偶数个,按照上面说的搞就好了. n为奇数时,要考虑最后中间那个字母.交换法可以证明,其实是贪心最后没有转化掉的字母. #include<bits/stdc++.h> using namespace std; typedef long long ll; ; char s[LEN]; ]; //#define LOCAL int main()…
A string is called palindrome if it reads the same from left to right and from right to left. For example "kazak", "oo", "r" and "mikhailrubinchikkihcniburliahkim" are palindroms, but strings "abb" and &qu…
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 计算出来每个字母出现的次数. 把字典序大的奇数出现次数的字母换成字典序小的奇数出现次数的字母贪心即可. 注意只有一个字母的情况 然后贪心地把字典序小的字母放在前面就好 [代码] #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--) #defin…
C. Palindrome Transformation time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Nam is playing with a string on his computer. The string consists of n lowercase English letters. It is meaningl…
  C. Palindrome Again !!   time limit per test 1 second memory limit per test 64 megabytes input standard input output standard output Given string with N characters, your task is to transform it to a palindrome string. It's not as easy as you may th…
练习string 最小变换次数下,且字典序最小输出回文串. #include <cstdio> #include <cstring> #include <cmath> #include <iostream> #include <algorithm> #include<deque> #include<vector> using namespace std; ; const double PI = acos(-1.0); ;…
题意: 在原字符串中修改数量最少,然后保证最小字典序. #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) { fo…
[链接] 我是链接,点我呀:) [题意] 光标一开始在p的位置 你可以用上下左右四个键位移动光标(左右)或者更改光标所在的字符(上下增加或减少ascill码) 问你最少要操作多少次才能使得字符串变成回文 [题解] 首先把字符串分成两个部分 1..n/2 和 n/2+1..n这两个部分 (如果n是奇数比较特殊,右半部分是n/2+2..n) 然后如果p落在右半部分那个区间的话 就让它做一下对称 到左半部分来 因为不可能从右边那个区间移动到左边那个区间的(跨越n到达1),那样做太不划算 这两个区间其实…
根据数据范围,暴力可以解决,对每一个串,找与其互为回文的串,或者判断自身是否为回文串,然后两两将互为回文的串排列在头尾,中间放且只能最多放一个自身为回文串的串,因为题目说每个串都是不同的 #include<bits/stdc++.h> using namespace std; #define lowbit(x) ((x)&(-x)) typedef long long LL; ]; ], self[], s[], chosen[]; void run_case() { int n, m…