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的更多相关文章

  1. 【Codeforces718C】Sasha and Array 线段树 + 矩阵乘法

    C. Sasha and Array time limit per test:5 seconds memory limit per test:256 megabytes input:standard ...

  2. codeforces 719E E. Sasha and Array(线段树)

    题目链接: E. Sasha and Array time limit per test 5 seconds memory limit per test 256 megabytes input sta ...

  3. Sasha and Array

    Sasha and Array time limit per test 5 seconds memory limit per test 256 megabytes input standard inp ...

  4. 【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 ...

  5. 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 ...

  6. 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 ...

  7. CF719E. Sasha and Array [线段树维护矩阵]

    CF719E. Sasha and Array 题意: 对长度为 n 的数列进行 m 次操作, 操作为: a[l..r] 每一项都加一个常数 C, 其中 0 ≤ C ≤ 10^9 求 F[a[l]]+ ...

  8. 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} 然后就 ...

  9. CF1109D Sasha and Interesting Fact from Graph Theory

    CF1109D Sasha and Interesting Fact from Graph Theory 这个 \(D\) 题比赛切掉的人基本上是 \(C\) 题的 \(5,6\) 倍...果然数学计 ...

随机推荐

  1. 04_Storm编程上手_WordCount集群模式运行

    1. 要解决的问题:代码打包 前一篇的代码,在IDEA中通过maven工程创建,通过IDEA完成代码打包 1)File -> Project Structure  2) 选择Artifacts, ...

  2. SVN 与Eclipse 关联 || 安装beyond 插件

    1.让本地svn代码与库建立联系   右击项目名称,Team -  share project 2.本地svn版本一般与Eaclipse svn插件 版本一致!http://subclipse.tig ...

  3. MongoDB3.xxx 用户创建

    启动MongoDB前需要关闭配置文件中的auth选项,否则不能创建用户 首先创建用户管理用户 use admin db.createUser({user:'admin',pwd:'123456', r ...

  4. R-模式(mode)和类(class)

    数据模式:mode函数显示任何对象的模式.常见的单个的对象模式是逻辑型(Logical).数值型(Numeric).字符型(Character). 常用到的数据模式是列表(list). 逻辑型:TRU ...

  5. 2-1 RHEL6.5 环境搭建与部署

    第二部分:Linux常见服务管理 2-1 RHEL6.5 环境搭建与部署 第二部分主要讲解的是开源服务搭建 学习方法与注意事项: 1. 端正态度,开始学习 2. 认真完成作业和实验(并详细记录) 3. ...

  6. Mac下新安装的MySQL无法登陆root用户解决方法

      一 设置MySQL命令行搜索路径 0.苹果->系统偏好设置->最下边点mysql 在弹出页面中 启动mysql服务 1.打开终端,输入: sudo vi ~/.bash_profile ...

  7. Ansible 小手册系列 十九(常见指令表)

    Play 指令 说明 accelerate 开启加速模式 accelerate_ipv6 是否开启ipv6 accelerate_port 加速模式的端口 always_run   any_error ...

  8. 缓存LruCache简单创建和使用

    LruCache一般使用: /** * 总容量为当前进程的1/8,单位:KB * sizeOf():计算缓存对象的大小,单位要一致 * entryRemoved():移除旧缓存时调用 */ int m ...

  9. Spring Framework Artifacts

    GroupId ArtifactId Description org.springframework spring-aop Proxy-based AOP support org.springfram ...

  10. 2018-2019-2 网络对抗技术 20165202 Exp6 信息搜集与漏洞扫描

    博客目录 一.实践目标 二.实践内容 各种搜索技巧的应用 DNS IP注册信息的查询 基本的扫描技术:主机发现.端口扫描.OS及服务版本探测.具体服务的查点 漏洞扫描:会扫,会看报告,会查漏洞说明,会 ...