CF1109B Sasha and One More Name
CF1109B Sasha and One More Name
- 构造类题目.仔细看样例解释能发现点东西?
- 结论:答案只可能是 \(Impossible,1,2\) .
- \(Impossible:\) 有 \(n\) 个或 \(n-1\) 个相同的字母,显然无法拼出另一个回文串.(样例3)
- \(1:\) \(Cut\) \(1\) 次,相当于是做了原串的一个循环排列. \(O(n^2)\) 对所有循环排列验证是否符合要求即可.(样例4)
- \(2:\) 在原串中找出一段 \(len<n/2\) 的前缀以及与它等长的后缀,将它们 \(Cut\) 出后交换.若所有的前缀与对应交换后都不符合要求,则一定是 \(Impossible\) 对应的两种局面,否则至少有一个前缀 \(pre\) 满足 \(pre!=inverse(pre)\),即它对应的 \(suf\) ,交换两者即得一个合法的解.(样例1)
- 只需判断是否为前 \(2\) 种情况,时间复杂度为 \(O(n^2)\) .
#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的更多相关文章
- 【Codeforces718C】Sasha and Array 线段树 + 矩阵乘法
C. Sasha and Array time limit per test:5 seconds memory limit per test:256 megabytes input:standard ...
- codeforces 719E E. Sasha and Array(线段树)
题目链接: E. Sasha and Array time limit per test 5 seconds memory limit per test 256 megabytes input sta ...
- Sasha and Array
Sasha and Array time limit per test 5 seconds memory limit per test 256 megabytes input standard inp ...
- 【codeforces 718 C&D】C. Sasha and Array&D. Andrew and Chemistry
C. Sasha and Array 题目大意&题目链接: http://codeforces.com/problemset/problem/718/C 长度为n的正整数数列,有m次操作,$o ...
- Codeforces Round #539 (Div. 2) - D. Sasha and One More Name(思维)
Problem Codeforces Round #539 (Div. 2) - D. Sasha and One More Name Time Limit: 1000 mSec Problem ...
- Codeforces Round #539 (Div. 2) - C. Sasha and a Bit of Relax(思维题)
Problem Codeforces Round #539 (Div. 2) - C. Sasha and a Bit of Relax Time Limit: 2000 mSec Problem ...
- CF719E. Sasha and Array [线段树维护矩阵]
CF719E. Sasha and Array 题意: 对长度为 n 的数列进行 m 次操作, 操作为: a[l..r] 每一项都加一个常数 C, 其中 0 ≤ C ≤ 10^9 求 F[a[l]]+ ...
- Codeforces 1109D Sasha and Interesting Fact from Graph Theory (看题解) 组合数学
Sasha and Interesting Fact from Graph Theory n 个 点形成 m 个有标号森林的方案数为 F(n, m) = m * n ^ {n - 1 - m} 然后就 ...
- CF1109D Sasha and Interesting Fact from Graph Theory
CF1109D Sasha and Interesting Fact from Graph Theory 这个 \(D\) 题比赛切掉的人基本上是 \(C\) 题的 \(5,6\) 倍...果然数学计 ...
随机推荐
- 你不知道的东西! c# == 等于运算符 和 Object.Equals()
最近在看 高级点的程序员必看的 CLR via C# 书中说解释了 Object.Equals() 方法的实现, 其中具体的实现用的是 == 运算符 ! 以前就对 == 运算符 的具体 ...
- C# Page基础功能,用于各页面继承
IBasePage.cs文件 /// <summary> /// 用于页面或用户控件 /// </summary> public interface IBasePage { / ...
- centos添加php及mysql环境变量
在Linux CentOS系统上安装完php和MySQL后,为了使用方便,需要将php和mysql命令加到系统命令中,如果在没有添加到环境变量之前,执行 “php -v”命令查看当前php版本信息时时 ...
- 使用ssm整合是项目启动tomcat报错java.lang.IndexOutOfBoundsException
解决办法:删除.m2文件夹下的全部仓库,然后重启myeclipse,对项目进行maven project.问题解决. 在没有这样做时,除了tomcat启动会失败,项目还有会报如下错误: ①cvc-co ...
- C++(三十一) — 静态成员变量、静态成员函数
1.静态成员变量 类的静态成员变量是,由该类的所以对象共同维护和使用的数据成员,每个类只有一个副本,是类数据成员的一种特例.采用 static 关键字声明. 目的:实现同一类中不同对象之间的数据共享. ...
- Python连接SQLite数据库代码
import sqlite3 # create database conn = sqlite3.connect('test.db') #不存在就创建后再打开 print ("Opened d ...
- 搞懂分布式技术5:Zookeeper的配置与集群管理实战
搞懂分布式技术5:Zookeeper的配置与集群管理实战 4.1 配置文件 ZooKeeper安装好之后,在安装目录的conf文件夹下可以找到一个名为“zoo_sample.cfg”的文件,是ZooK ...
- nyoj——297(期望)
GoroSort 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描述 Goro has 4 arms. Goro is very strong. You don't me ...
- angularJS----filter
angularJS过滤器 过滤器(filter)正如其名,作用就是接收一个输入(隐式的接收数据源),通过某个规则进行处理,然后返回处理后的结果.主要用在数据的格式化上,例如获取一个数组中的子集,对数组 ...
- SQL server 数据库用户表名称
转自(http://blog.163.com/jlj_sk/blog/static/22579293200861422833924/) 取得SQL server 数据库中 所有用户表名称 select ...