标签:sdi element line 要求 tchar air ali 解释 交换
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pii pair<int,int>
inline int read()
{
int x=0;
bool pos=1;
char ch=getchar();
for(;!isdigit(ch);ch=getchar())
if(ch=='-')
pos=0;
for(;isdigit(ch);ch=getchar())
x=x*10+ch-'0';
return pos?x:-x;
}
const int MAXN=5e3+10;
int n;
char s[MAXN];
int t[MAXN];
bool judge_imp()
{
for(int i=1;i<=n;++i)
if(++t[s[i]]>=n-1)
return true;
return false;
}
char curs[MAXN];
bool judge_palindrome()
{
for(int i=1;i<=n/2;++i)
if(curs[i]!=curs[n+1-i])
return false;
return true;
}
bool judge_unique()
{
for(int i=1;i<=n;++i)
if(curs[i]!=s[i])
return true;
return false;
}
bool judge_one()
{
for(int pos=2;pos<=n;++pos)// s[pos] is the first element
{
int p=0;
for(int i=pos;i<=n;++i)
curs[++p]=s[i];
for(int i=1;i<pos;++i)
curs[++p]=s[i];
if(judge_palindrome() && judge_unique())
return true;
}
return false;
}
int main()
{
scanf("%s",s+1);
n=strlen(s+1);
if(judge_imp())
return puts("Impossible")&0;
if(judge_one())
return puts("1")&0;
puts("2");
return 0;
}
CF1109B Sasha and One More Name
标签:sdi element line 要求 tchar air ali 解释 交换
原文地址:https://www.cnblogs.com/jklover/p/10390273.html