【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 ...
随机推荐
- Fragment进阶(四)----->參数传递3种写法
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/ ...
- Catalyst 2960 and 2960-S Software -Configuring VTP
http://www.cisco.com/c/en/us/td/docs/switches/lan/catalyst2960/software/release/12-2_53_se/configura ...
- golang——(strings包)常用字符串操作函数
(1)func HasPrefix(s, prefix string) bool 判断字符串s是否有前缀字符串prefix: (2)func HasSuffix(s, suffix string) b ...
- [转]"RDLC"报表-参数传递及主从报表
本文转自:http://www.cnblogs.com/yjmyzz/archive/2011/09/19/2180940.html 今天继续学习RDLC报表的“参数传递”及“主从报表” 一.先创建D ...
- https 结合使用 对称加密和非对称加密
(一)对称加密(Symmetric Cryptography) ---共享密钥加密 对称加密是最快速.最简单的一种加密方式,加密(encryption)与解密(decryption)用的是同样的密钥( ...
- bootstrap-paginator基于bootstrap的分页插件
bootstrap-paginator基于bootstrap的分页插件 GitHub 官网地址:https://github.com/lyonlai/bootstrap-paginator 步骤 引包 ...
- 【VB】api实现窗口最小化
Const WM_SYSCOMMAND = &H112 Const SC_MINIMIZE = &HF020& SendMessage hWnd, WM_SYSCOMMAND, ...
- 删除git上已经提交的文件
1.先查看有哪些文件可以删除,但是不真执行删除 git rm -r -n job-executor-common/target/* -r 递归移除目录 -n 加上这个参数,执行命令时,是不会删除任何 ...
- css3基础篇一
CSS3 选择器 选择器 例子 例子描述 CSS .class .intro 选择 class="intro" 的所有元素. 1 #id #firstname 选择 id=&quo ...
- javaee IO流打印一行的方式
package Dayin; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.F ...