CF- 798A. Mike and palindrome - 思维
2017-04-22 21:01
375 查看
1.题目描述:
A. Mike and palindrome
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Mike has a string s consisting of only lowercase English letters. He wants to change
exactly one character from the string so that the resulting one is a palindrome.
A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa",
"aba", "abccba" are palindromes, but strings "codeforces",
"reality", "ab" are not.
Input
The first and single line contains string s (1 ≤ |s| ≤ 15).
Output
Print "YES" (without quotes) if Mike can change exactly one character so that the resulting
string is palindrome or "NO" (without quotes) otherwise.
Examples
input
output
input
output
input
output
2.题意概述:
定义一个变量是合法的当且仅当它回文。给你一个字符串,麦克一定要修改其中一个字符,问你是否存在某种修改使得它成为一个变量。
3.解题思路:
坑的地方在于它一定会修改一次,因此如果字符串本身就是回文的且为偶数串则不管怎么修改它都不再是回文串,注意这个地方应该就没有坑点了。
4.AC代码:
A. Mike and palindrome
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Mike has a string s consisting of only lowercase English letters. He wants to change
exactly one character from the string so that the resulting one is a palindrome.
A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa",
"aba", "abccba" are palindromes, but strings "codeforces",
"reality", "ab" are not.
Input
The first and single line contains string s (1 ≤ |s| ≤ 15).
Output
Print "YES" (without quotes) if Mike can change exactly one character so that the resulting
string is palindrome or "NO" (without quotes) otherwise.
Examples
input
abccaa
output
YES
input
abbcca
output
NO
input
abcda
output
YES
2.题意概述:
定义一个变量是合法的当且仅当它回文。给你一个字符串,麦克一定要修改其中一个字符,问你是否存在某种修改使得它成为一个变量。
3.解题思路:
坑的地方在于它一定会修改一次,因此如果字符串本身就是回文的且为偶数串则不管怎么修改它都不再是回文串,注意这个地方应该就没有坑点了。
4.AC代码:
#include <bits/stdc++.h> #define INF 0x3f3f3f3f #define maxn 100100 #define lson root << 1 #define rson root << 1 | 1 #define lent (t[root].r - t[root].l + 1) #define lenl (t[lson].r - t[lson].l + 1) #define lenr (t[rson].r - t[rson].l + 1) #define N 1111 #define eps 1e-6 #define pi acos(-1.0) #define e exp(1.0) using namespace std; const int mod = 1e9 + 7; typedef long long ll; typedef unsigned long long ull; char s[20]; int main() { scanf("%s",s); int len=strlen(s); int temp=0; for(int i=0;i<len/2;i++) { if(s[i]==s[len-1-i]) continue; temp++; } if(temp==1||(temp==0&&len%2)) printf("YES\n"); else printf("NO\n"); }
相关文章推荐
- CF- 798A. Mike and palindrome - 思维
- cf(思维,数学)
- CF446B DZY Loves Modification 【思维/优先队列】By cellur925
- CF 551c 二分搜索+思维题
- CF - 652A. Gabriel and Caterpillar 模拟+思维
- 【CF】-Chips(思维)
- cf(思维题)
- CF - 805C. Find Amir - 贪心思维+构造
- CF--- PROBLEM 620 E 【思维 + DFS序 + 二进制状态】
- 【CF】--Buggy Robot (思维)
- CF - 749D 二分 + 思维
- CF - 807C. Success Rate - 二分+思维+数学
- CF 599D 思维
- CF - 519D. A and B and Interesting Substrings - 前缀和思维+map
- CF 452B 4-point polyline(思维)
- CF 915E. Physical Education Lessons 思维+set维护
- CF - 779A. Pupils Redistribution 贪心+思维
- CF - 584B. Kolya and Tanya - 快速幂+思维
- CF 767C.Garland 思维,树三等分
- cf 226b 唯美思维题~.cpp