Codeforces 505 A Mr. Kitayuta's Gift【暴力】
题意:给出一个字符串,可以向该字符串的任意位置插入一个字母使其变成回文串
因为字符串的长度小于10,枚举插入的字母,和要插入的位置,再判断是否已经满足回文串
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
using namespace std; typedef long long LL;
const int INF = (<<)-;
const int mod=;
const int maxn=;
char t[],s[];
int n; bool is(){
for(int l=,r=n;l<r;l++,r--){
if(t[l]!=t[r])
return false;
}
return true;
} int main(){
cin>>s;
n=strlen(s);
for(char ch='a';ch<='z';ch++){//枚举那个要被替换的字母 for(int i=;i<=n;i++){ //枚举插入的位置
int len=; for(int j=;j<i;j++) t[len++]=s[j];
t[len++]=ch;
for(int j=i;j<n;j++) t[len++]=s[j];
if(is()) {
printf("%s\n",t);
return ;
}
}
}
printf("NA\n");
return ;
}
Codeforces 505 A Mr. Kitayuta's Gift【暴力】的更多相关文章
- Codeforces 505A Mr. Kitayuta's Gift 暴力
A. Mr. Kitayuta's Gift time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Codeforces Round #286 (Div. 2)A. Mr. Kitayuta's Gift(暴力,string的应用)
由于字符串的长度很短,所以就暴力枚举每一个空每一个字母,出现行的就输出.这么简单的思路我居然没想到,临场想了很多,以为有什么技巧,越想越迷...是思维方式有问题,遇到问题先分析最简单粗暴的办法,然后一 ...
- 【Codeforces 506E】Mr.Kitayuta’s Gift&&【BZOJ 4214】黄昏下的礼物 dp转有限状态自动机+矩阵乘法优化
神题……胡乱讲述一下思维过程……首先,读懂题.然后,转化问题为构造一个长度为|T|+n的字符串,使其内含有T这个子序列.之后,想到一个简单的dp.由于是回文串,我们就增量构造半个回文串,设f(i,j, ...
- 水题 Codeforces Round #286 (Div. 2) A Mr. Kitayuta's Gift
题目传送门 /* 水题:vector容器实现插入操作,暴力进行判断是否为回文串 */ #include <cstdio> #include <iostream> #includ ...
- 【CF506E】Mr. Kitayuta's Gift dp转有限状态自动机+矩阵乘法
[CF506E]Mr. Kitayuta's Gift 题意:给你一个字符串s,你需要在s中插入n个字符(小写字母),每个字符可以被插在任意位置.问可以得到多少种本质不同的字符串,使得这个串是回文的. ...
- codeforces Round 286# problem A. Mr. Kitayuta's Gift
Mr. Kitayuta has kindly given you a string s consisting of lowercase English letters. You are asked ...
- CodeForces 506B/505D Mr. Kitayuta's Technology
Portal:http://codeforces.com/problemset/problem/506/B http://codeforces.com/problemset/problem/505/D ...
- codeforces 505C C. Mr. Kitayuta, the Treasure Hunter(dp)
题目链接: C. Mr. Kitayuta, the Treasure Hunter time limit per test 1 second memory limit per test 256 me ...
- codeforces 505A. Mr. Kitayuta's Gift 解题报告
题目链接:http://codeforces.com/problemset/problem/505/A 题目意思:给出一个长度不大于10的小写英文字符串 s,问是否能通过在字符串的某个位置插入一个字母 ...
随机推荐
- 解决vsftpd日志时间问题
解决vsftpd日志时间问题 发布时间:August 29, 2008 分类:Linux <你必须承认土也是一种艺术> <Linux下查看Apache的请求数> 最近发现vsf ...
- POJ 1742
Coins Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 27580 Accepted: 9335 Descriptio ...
- POJ 2039
#include<iostream> #include<stdio.h> #include<string> #define MAXN 20 using namesp ...
- Linux之select系统调用_1
SYNOPSIS /* According to POSIX.1-2001 */ #include <sys/select.h> /* According to earlier stand ...
- JS中基本类型与包装类型的关系
对于JS中一些类型的转化的东西,自己测试并得出的结论,有错误的地方请大大们留言. 不多废话,直接贴代码,测试请直接拷贝全部代码: <!DOCTYPE html> <html> ...
- MVC中前台如何向后台传递数据------$.get(),$post(),$ajax(),$.getJSON()总结
一.引言 MVC中view向controller传递数据的时候真心是一个挺让人头疼的一件事情.因为原理不是很懂只看一写Dome,按葫芦画瓢只能理解三分吧. 二.解读Jquery个Ajax函数 $.ge ...
- C#DataGridView 美化
private void dataGridView(DataGridView dataGridView) { System.Windows.Forms.DataGridViewCellStyle da ...
- 怎么修改mysql密码
1.用root 进入mysql后mysql>set password =password('你的密码');mysql>flush privileges; 2.使用GRANT语句 mysql ...
- android 矩阵处理类:Matrix
在Android中,对图片的处理需要使用到Matrix类,Matrix是一个3 x 3的矩阵,他对图片的处理分为四个基本类型: 1.Translate 2.Scale 3.Rotate 4.Skew ...
- 高通/苹果/联发科:手机CPU那些事
如今人们买手机,都比较关心采用了什么CPU,因为CPU直接决定了这台手机的性能,CPU之于手机就好比人的大脑,它是整台手机的控制中枢系统,也是逻辑部分的控制中心.又相当于车的发动机,发动机越强劲,车子 ...