专栏文章

题解:P12592 重生有惊喜

P12592题解参与者 1已保存评论 0

文章操作

快速查看文章及其快照的属性,并进行相关操作。

当前评论
0 条
当前快照
1 份
快照标识符
@mip7rpya
此快照首次捕获于
2025/12/03 07:33
3 个月前
此快照最后确认于
2025/12/03 07:33
3 个月前
查看原文

题意:

给你一个字符串让你判断是否能交换若干次变成回文串。

思路:

由于对此次数没要求我们就可以先不管原串如何,就直接判断字符串是否能成功成为回文串。

证明:

由于是可以将一个字符丢来丢去于是就是可以有原串任意排列,相当于以上的思路。

code:

CPP
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=100500;
int t,a[N],n;
string as;
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>t;
	while(t--)
	{
		cin>>as;
		n=as.length();
		as=' '+as;
		memset(a,0,sizeof(a));
		for(int i=1;i<=n;i++)
		{
			a[as[i]]++;
		}
		int f=0;
		for(int i=1;i<=200;i++)
		{
			if(a[i]%2!=0)
			{
				f++;
			}
		}
		if(f<=n%2)
		{
			cout<<"Yes\n";
		}
		else
		{
			cout<<"No\n";
		}
	}
	
	return 0;
}

评论

0 条评论,欢迎与作者交流。

正在加载评论...