博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 6264(思维)
阅读量:4455 次
发布时间:2019-06-07

本文共 1547 字,大约阅读时间需要 5 分钟。

题面:

Problem A. Super-palindrome

You are given a string that is consistedof lowercase English alphabet. You are supposed to change it into asuper-palindrome string in minimum steps. You can change one character instring to another letter per step.

A string is called asuper-palindrome string if all its substrings with an odd length are palindromestrings. That is, for a string s, if its substring si···j satisfies j i + 1 is oddthen si+k = sjk fork= 0,1,··· ,ji + 1.

Input

The first line contains an integer T (1 ≤ T ≤100) representing the number of test cases.

For each test case, the only line containsa string, which consists of only lowercase letters. It is guaranteed that thelength of string satisfies 1 ≤ |s| ≤ 100.

Output

For each test case, print one line with aninteger refers to the minimum steps to take.

Example

standard input

 

standard output

3
ncncn
aaaaba
aaaabb

0

1

2

 

Explanation

For second testcase aaaaba, just change letter bto a in one step.

    
    题目描述:给你一个字符串,问你需要更改里面多少个字符,使得原字符串变为一个超级回文串。超级回文串是指字串为奇数长度的都为回文串的串。
    题目分析:分析样例之后容易得出,对于这样一个超级回文串,只有两种情况可以满足。
    
一为串内所有的字符都是相同的。
    二是该串只有两种字符组成,且这两种字符是交替出现的。
     能够发现这个规律的话,这道题就可以进行模拟。因为数据范围很小(100而已),因此我们可以直接进行暴力的匹配。
    我们首先先将串中不相同的字符储存起来,枚举两种字符的种类,再跟原串进行匹配,最后去最小的更改量即可。

   
总结:最近做字符串算法做得有些多了,上来拿到题直接就往Manache上面去想了(还好队友很给力),对于这些题还得拓宽思维才行!!
    
#include 
#define maxn 1005using namespace std;string str,tmp;bool vis[maxn];int main(){ int t; cin>>t; while(t--){ cin>>str; memset(vis,0,sizeof(vis)); for(int i=0;i

转载于:https://www.cnblogs.com/Chen-Jr/p/11007303.html

你可能感兴趣的文章
使用PullToRefresh实现下拉刷新和上拉加载
查看>>
透明度百分比与十六进制转换
查看>>
HBase表预分区
查看>>
arcgis desktop 10.1 license manager无法启动问题解决
查看>>
django select_related() 联表查询
查看>>
mysql 常用,使用经验
查看>>
NSBundle,UIImage,UIButton的使用
查看>>
vue-cli3 中console.log报错
查看>>
GridView 中Item项居中显示
查看>>
UML类图五种关系与代码的对应关系
查看>>
如何理解作用域
查看>>
从无到满意offer,你需要知道的那些事
查看>>
P1516 青蛙的约会 洛谷
查看>>
SDOI2011 染色
查看>>
JQuery EasyUI combobox动态添加option
查看>>
面向连接的TCP概述
查看>>
前端快捷方式 [记录]
查看>>
亲测可用,解决端口被占用的指令!!
查看>>
MySQL--视图、触发器、事务、存储过程、内置函数、流程控制、索引
查看>>
Django--数据库查询操作
查看>>