英语翻译

ABC

2022 02.14

https://acs.jxnu.edu.cn/contest/24/board/challenge/A

描述:

Recently, the students of School 179 have developed a unique algorithm, which takes in a binary string ss as input. However, they soon found out that if some substring tt of ss is a palindrome of length greater than 1, the algorithm will work incorrectly. Can the students somehow reorder the characters of ss so that the algorithm will work correctly on the string?

A binary string is a string where each character is either 0 or 1.

A string aa is a substring of a string bb if aa can be obtained from bb by deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end.

A palindrome is a string that reads the same backwards as forwards.

最近,179学校的学生开发了一种独特的算法,将二进制字符串s作为输入。然而,他们很快发现,如果s的某个子串t是长度大于1的回文,算法将无法正常工作。学生们能否以某种方式重新排列s的字符,以便算法能正确地处理字符串?

二进制字符串是每个字符为0或1的字符串。

如果aa可以通过删除开头的几个(可能是零或全部)字符和结尾的几个(可能是零或全部)字符从b中获得,则字符串a是字符串b的子字符串。

回文是一个前后读相同的字符串。

输入:

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1001≤t≤100). Description of the test cases follows.

The first line of each test case contains a single integer nn (1≤n≤1001≤n≤100) — the length of the string ss.

The second line of each test case contains the string ss of length nn consisting only of the characters 0 and 1.

输出:

For each test case, print YES (case-insensitive) if it is possible to reorder the characters of ss so that there are no substrings that are a palindrome of length greater than 1, or NO (case-insensitive) otherwise.

样例输入:

4
1
1
2
10
2
01
4
1010

复制

样例输出:

YES
YES
YES
NO

复制

注释:

In the first three test cases, the given strings do not contain palindromes of length greater than 1, so the answers are YES.

In the last test case, it is impossible to reorder the characters so that the string does not contain palindromes of length greater than 1, so the answer is NO.

在前三个测试用例中,给定的字符串不包含长度大于1的回文,因此答案是肯定的。

在最后一个测试用例中,不可能对字符进行重新排序,以便字符串不包含长度大于1的回文,因此答案是否定的。

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
char b[10001];
int main(){
	int n;
	cin>>n;
	while(n--){
		int a;
		memset(b,0,sizeof(b)); 
		scanf("%d",&a);
		scanf("%s",b);
		if(a>2||b[0]==b[1]){
			printf("NO\n");
		}
		else{
			printf("YES\n");
		}
	}
	
	
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

辉哥哥哟

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值