codeforce-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…
练习string 最小变换次数下,且字典序最小输出回文串. #include <cstdio> #include <cstring> #include <cmath> #include <iostream> #include <algorithm> #include<deque> #include<vector> using namespace std; ; const double PI = acos(-1.0); ;…
C. Make Palindrome Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/600/problem/C Description A string is called palindrome if it reads the same from left to right and from right to left. For example "kazak", "oo&q…
要保证变化次数最少就是出现次数为奇数的相互转化,而且对应字母只改变一次.保证字典序小就是字典序大的字母变成字典序小的字母. 长度n为偶数时候,次数为奇数的有偶数个,按照上面说的搞就好了. n为奇数时,要考虑最后中间那个字母.交换法可以证明,其实是贪心最后没有转化掉的字母. #include<bits/stdc++.h> using namespace std; typedef long long ll; ; char s[LEN]; ]; //#define LOCAL int main()…
题目链接:http://codeforces.com/contest/600/problem/C C. Make Palindrome time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A string is called palindrome if it reads the same from left to right an…
A positive integer is called a palindrome if its representation in the decimal system is the same when read from left to right and from right to left. For a given positive integer K of not more than 1000000 digits, write the value of the smallest pal…
http://codeforces.com/problemset/problem/600/C: 题意:给你一个小写字母组成的英文串,将它转换为回文串,要求,改变的字母的个数最小,移动字母不算改变字母. 所得的串字典序是最小的.最后输出所得到的串. 思路:要求改变的字母数最小那么用贪心的思想,就把原来的字母尽可能多的填入要求的串中. 首先,先把原串中的字母统计出来,开个数组存对应的字符的个数,然后从'a'开始循环,如果对应字母的个数大于1: 如果是偶数个的话,就在所求串两端一边加一个,可以正好加完…
如果自己是回文串可以做中心 如果一个串和另一个串的转置相等则可以凑一对 优先配对 #include <bits/stdc++.h> using namespace std; int n,m,u[105]; string str[105]; vector <int> a,b; signed main() { ios::sync_with_stdio(false); cin>>n>>m; for(int i=1;i<=n;i++) cin>>s…
题意:给定k个长度为n的字符串,每个字符串有一个魅力值ai,在k个字符串中选取字符串组成回文串,使得组成的回文串魅力值最大. 分析: 1.若某字符串不是回文串a,但有与之对称的串b,将串a和串b所有的魅力值分别从大到小排序后,若两者之和大于0,则可以放在回文串的两边. 2.若某字符串是回文串,将其魅力值从大到小排序后,两两依次分析:(mid---可能放在回文串中间的串的最大魅力值) (1)若两个数都是正的,那么就将其放在两边,并将结果计入ans.(ans---回文串两边的串的魅力值之和) (2)…
600A - Extract Numbers    20171106 字符串处理题,稍微注意点细节就能水过 #include<stdlib.h> #include<stdio.h> #include<math.h> #include<vector> #include<cstring> #include<iostream> #include<algorithm> using namespace std; string s;i…