备战省赛组队训练赛第二场

本文探讨了两个有趣的算法挑战:“超级回文”和“Hakase与Nano的鹅卵石游戏”。在“超级回文”中,目标是通过最少步骤将字符串转化为所有奇数长度子串均为回文的超级回文字符串。而在“鹅卵石游戏”中,Hakase和Nano轮流取走鹅卵石包中的鹅卵石,Hakase必须连续两轮遵循规则取石,文章分析了在最优策略下Hakase是否能赢得游戏。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

问题 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

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值