Evil Straw Warts Live Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 1799   Accepted: 523 Description A palindrome is a string of symbols that is equal to itself when reversed. Given an input string, not necessarily a palindrome, comput…
Description A palindrome is a string of symbols that is equal to itself when reversed. Given an input string, not necessarily a palindrome, compute the number of swaps necessary to transform the string into a palindrome. By swap we mean reversing the…
这道题目我用了一上午才做出来,还是看的别人的思路,尽管没有看代码做的有点慢.代码能力还是得加强啊.思维 得缜密.不能想当然,要有根据,写上的代码要有精确度.省的以后还得慢慢调试 思路:贪心.每次都查看两端位置上的字母是否相等.若不相等就在里面查找能使他们相等且所需移动位置最少的那 个.然后交换.记录交换的距离,贪心的离最后一个由近及远找与第一个位置相等的.同理贪心从第一个位置找和最 后一个位置相等且离第一个位置近期的. . .感觉这样的方法确实能够,可是并不会证明这样的策略的正确性.. . 代码…
Problem D: Evil Straw Warts Live A palindrome is a string of symbols that is equal to itself when reversed. Given an input string, not necessarily a palindrome, compute the number of swaps necessary to transform the string into a palindrome. By  swap…
题目大意:给一个字符串,判断是否能通过交换字母构成回文,如果能,计算所需的最小交换次数. 如果字符串中出现奇数次的字母的个数>1,则不能构成回文.然后...就没思路了...看网上说用贪心的思想先从两端开始考虑,决定两端的字母后再缩小问题范围直至字符串长度<=2.可是看网上的代码都是只考虑了两端字母,而没有考虑其他可能的情况,如mdcfamcda,如果两端都变为m的话需要交换3次,两端都变为a的话需要交换4次,可是如果变为d的话只需要交换两次,但是网上的代码没考虑这种情况竟然AC了,为什么?是测…
/* * POJ_1159.cpp * * Created on: 2013年10月29日 * Author: Administrator */ #include <iostream> #include <cstdio> #include <cmath> #include <algorithm> #include <cstring> using namespace std; const int maxn = 5005; char str1[max…
Evil Straw Warts Live Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 1144   Accepted: 330 Description A palindrome is a string of symbols that is equal to itself when reversed. Given an input string, not necessarily a palindrome, comput…
感悟: 首先我要Orz一下qsc,我在网上很难找到关于acm的教学视频,但偶然发现了这个,感觉做的很好,链接:戳戳戳 感觉这种花费自己时间去教别人的人真的很伟大. manacher算法把所有的回文都变成了奇数形式的,所以判断的时候就很方便了,并且p[i]数组存的是:以第i个为中心,他的回文半径是多少.这算法其中还有id和mx,mx是对于一个位置id回文串最长半径是mx.2*id-i是以id为中心关于i对称的那个位置,mx-i是回文串半径长度. 还有qsc推荐的题 POJ 1159 Palindr…
题目链接:http://poj.org/problem?id=1159 题意:给定一个长度为N的字符串.问你最少要添加多少个字符才能使它变成回文串. 思路:最少要添加的字符个数=原串长度-原串最长回文子串长度.对于求原串最长回文子串长度用的是DP的经典问题LCS最长公共子序列的做法. 设原串为S,原串的逆串为S‘,那么原串的最长回文子串长度=S和S'的最长公共子序列长度. 由于N的范围最大是5000,所以5000*5000的数组开不下,所以需要用到滚动数组来求.[关于原串求最长回文子串用的Man…
题目链接:http://poj.org/problem?id=3974 题意:求出给定字符串的最长回文串长度. 思路:裸的Manacher模板题. #include<iostream> #include<cstdio> #include<cstring> #include<string> #include<cmath> #include<algorithm> using namespace std; +; typedef long l…