问题 A: Super-palindrome
时间限制: 1 Sec 内存限制: 128 MB
提交: 693 解决: 279
[提交] [状态] [命题人:admin]
题目描述
You are given a string that is consisted of lowercase English alphabet. You are supposed to change it into a super-palindrome string in minimum steps. You can change one character in string to another letter per step.
A string is called a super-palindrome string if all its substrings with an odd length are palindrome strings. That is, for a string s, if its substring si...j satisfies j - i + 1 is odd then si+k = sj-k for k = 0,1,...,j-i+1.
输入
The fi rst line contains an integer T (1≤T≤100) representing the number of test cases.
For each test case, the only line contains a string, which consists of only lowercase letters. It is guaranteed that the length of string satisfies 1≤|s|≤100.
输出
For each test case, print one line with an integer refers to the minimum steps to take.
样例输入
复制样例数据
3
ncncn
aaaaba
aaaabb
样例输出
0
1
2
提示
For second test case aaaaba, just change letter b to a in one step.
超级回文:序列中奇数长度的子串都是回文序列,由这一点我们可以推出原序列中字符隔项相同,也就是下标为奇数的字符都是一样的,下标为偶数的字符都是一样的。如果下标为奇数/偶数的字符有不一样的话,我们就将字符全转换为出现次数最多的那个字符。(当时比赛做这题的时候,我就推出隔项字符相同,之后愣是不知怎么处理了,还好小学弟反应地快。唉~我脑子是生锈了嘛,还是需要接触新题,平常太懒)
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int maxn=110; int vis[maxn][maxn]; int main(){ int T; scanf("%d",&T); while(T--){ string s; cin>>s; int len=s.length(),mx1=0,mx2=0; map<char,int> mp1,mp2; for(int i=0;i<len;i++){ if(i%2==0){ mp1[s[i]]++; mx1=max(mx1,mp1[s[i]]); }else{ mp2[s[i]]++; mx2=max(mx2,mp2[s[i]]); } } printf("%d\n",len-mx1-mx2); } return 0; }
问题 C: Hakase and Nano
时间限制: 1 Sec 内存限制: 128 MB
提交: 606 解决: 195
[提交] [状态] [命题人:admin]
题目描述
Hakase and Nano are playing an ancient pebble game (pebble is a kind of rock). There are n packs of pebbles, and the i-th pack contains ai pebbles. They take turns to pick up pebbles. In each turn, they can choose a pack arbitrarily and pick up at least one pebble in this pack. The person who takes the last pebble wins.
This time, Hakase cheats. In each turn, she must pick pebbles following the rules twice continuously.
Suppose both players play optimally, can you tell whether Hakase will win?
输入
The first line contains an integer T (1≤T≤20) representing the number of test cases.
For each test case, the fi rst line of description contains two integers n(1≤n≤106) and d (d = 1 or d = 2). If d = 1, Hakase takes first and if d = 2, Nano takes first. n represents the number of pebble packs.
The second line contains n integers, the i-th integer ai (1≤ai≤109) represents the number of pebbles in the i-th pebble pack.
输出
For each test case, print “Yes” or “No” in one line. If Hakase can win, print “Yes”, otherwise, print “No”.
样例输入
复制样例数据
2 3 1 1 1 2 3 2 1 1 2
样例输出
Yes No