【codeforces 798A】Mike and palindrome
【题目链接】:http://codeforces.com/contest/798/problem/A
【题意】
让你严格改变一个字符,使得改变后的字符串为一个回文串;
让你输出可不可能;
【题解】
直接无脑暴力改就好;
或者按照回文串的规则;
如果a[i]和a[n-i+1]不同则cnt++
然后看看最后cnt是不是恰好为1,或者为0然后字符串长度为奇数(那样中间那个字符可以任意改)
【Number Of WA】
0
【完整代码】
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 110;
string s;
int len;
bool ok(int l,int r)
{
if (l>=r) return true;
if (s[l]==s[r])
return ok(l+1,r-1);
else
return false;
}
int main()
{
//freopen("F:\\rush.txt","r",stdin);
ios::sync_with_stdio(false),cin.tie(0);//scanf,puts,printf�ͱ�����!
cin >> s;
len = s.size();
rep1(i,0,len-1)
{
char t = s[i];
for (char key = 'a';key<='z';key++)
if (key!=t)
{
s[i]=key;
if (ok(0,len-1))
return cout <<"YES"<<endl,0;
}
s[i] = t;
}
cout <<"NO"<<endl;
return 0;
}
【codeforces 798A】Mike and palindrome的更多相关文章
- 【codeforces 798B】Mike and strings
[题目链接]:http://codeforces.com/contest/798/problem/B [题意] 给你n个字符串; 每次操作,你可以把字符串的每个元素整体左移(最左边那个字符跑到最后面去 ...
- 【codeforces 798C】Mike and gcd problem
[题目链接]:http://codeforces.com/contest/798/problem/C [题意] 给你n个数字; 要求你进行若干次操作; 每次操作对第i和第i+1个位置的数字进行; 将 ...
- 【codeforces 798D】Mike and distribution
[题目链接]:http://codeforces.com/contest/798/problem/D [题意] 让你选一个下标集合 p1,p2,p3..pk 使得2*(a[p1]+a[p2]+..+a ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【19.77%】【codeforces 570D】Tree Requests
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【34.88%】【codeforces 569C】Primes or Palindromes?
time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【25.64%】【codeforces 570E】Pig and Palindromes
time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【44.19%】【codeforces 608D】Zuma
time limit per test2 seconds memory limit per test512 megabytes inputstandard input outputstandard o ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
随机推荐
- 【bzoj2038】[2009国家集训队]小Z的袜子(hose)(细致总结)
[bzoj2038][2009国家集训队]小Z的袜子(hose)(细致总结) Description 作为一个生活散漫的人,小Z每天早上都要耗费很久从一堆五颜六色的袜子中找出一双来穿.终于有一天,小Z ...
- hdoj-1896 stones
Stones Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Total Sub ...
- Tool-Java:Spring Tool Suite
ylbtech-Tool-Java:Spring Tool Suite Spring Tool Suite 1.返回顶部 2.返回顶部 3.返回顶部 4.返回顶部 5.返回顶部 0. ...
- java Collection接口
Collection 1——————Set子接口:无序,不允许重复. 2——————List子接口:有序,允许重复. Set和List对比: 1.set:检索元素的效率比较低,删除和插入效率比较高,删 ...
- itext 生成doc文档 小结(自己备忘)
1.引入maven <dependency> <groupId>com.lowagie</groupId> <artifactId>itext</ ...
- D - Garden
Problem description Luba thinks about watering her garden. The garden can be represented as a segmen ...
- tomcat启动时出现以前删除的项目,导致无法启动
com.sun.faces.config.ConfigureListener contextInitialized 解决: 进入到你自己的tomcat安装目录:C:\Program Files\Apa ...
- 总结java基础
第一章总结: 1.java的是sun公司(现甲骨文有限公司)于1995年推出的高级编程语言,java技术可以应用在几乎所有类型和规模的设备上,小到计算机芯片.蜂窝电话,大到超级计算机,无所不在. 2. ...
- 1、Visual Studio Code安装及Hello Word
一.环境初始化 1.下载 Visual Studio Code对应版本安装 2.下载.NET Core 2.0 SDK安装 3.安装Mono Debug 完成后界面如下: 二.创建控制 ...
- Android TV 选中高亮显示
1.开发Android TV APP, 使用遥控器选中按钮或者选着其它菜单 如果没有高亮显示,就看不出选中哪个按钮或者菜单 2.在drawable 添加 border_red.xml 设置选中高亮 & ...