https://codeforces.com/contest/1113/problem/D

题意

将一个回文串切成一段一段,重新拼接,组成一个新的回文串,问最少切几刀

题解

  • 首先无论奇偶串,最多只会切两刀
  • 然后对于偶数串,看看有没有循环回文串,有的话只需要切一刀

代码

#include<bits/stdc++.h>

using namespace std;
int n,m,i,j,ok,ans;
string s;
int main(){
cin>>s;n=s.size();
if(n%2)m=n/2+1;
else m=n/2;
ans=0;
for(i=2;i<=n/2;i++){
ok=1;
for(j=1;j<=i;j++){
if(s[j-1]!=s[n-i+j-1]){ok=0;break;}
}
if(!ok){
ans=2;
break;
}
}
if(!ans){
cout<<"Impossible"<<endl;
return 0;
}
s=s+s;
for(i=1;i<n;i++){
ok=1;
for(j=0;j<n;j++){
if(s[j]!=s[i+j]){ok=0;break;}
}
if(ok)continue;
ok=1;
for(j=0;j<n/2;j++){
if(s[i+j]!=s[n-1-j+i]){ok=0;break;}
}
if(ok){cout<<1<<endl;return 0;}
}
cout<<ans<<endl;
}

Codeforces Round #539 (Div. 2) D 思维的更多相关文章

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

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

  3. Codeforces Round #539 (Div. 2)

    Codeforces Round #539 (Div. 2) A - Sasha and His Trip #include<bits/stdc++.h> #include<iost ...

  4. Codeforces Round #539 (Div. 2) 题解

    Codeforces Round #539 (Div. 2) 题目链接:https://codeforces.com/contest/1113 A. Sasha and His Trip 题意: n个 ...

  5. 【CF1256】Codeforces Round #598 (Div. 3) 【思维+贪心+DP】

    https://codeforces.com/contest/1256 A:Payment Without Change[思维] 题意:给你a个价值n的物品和b个价值1的物品,问是否存在取物方案使得价 ...

  6. Codeforces Round #143 (Div. 2) (ABCD 思维场)

    题目连链接:http://codeforces.com/contest/231 A. Team time limit per test:2 seconds memory limit per test: ...

  7. Codeforces Round #395 (Div. 2)(A.思维,B,水)

    A. Taymyr is calling you time limit per test:1 second memory limit per test:256 megabytes input:stan ...

  8. Codeforces Round #416 (Div. 2)(A,思维题,暴力,B,思维题,暴力)

    A. Vladik and Courtesy time limit per test:2 seconds memory limit per test:256 megabytes input:stand ...

  9. Codeforces Round #533 (Div. 2) C.思维dp D. 多源BFS

    题目链接:https://codeforces.com/contest/1105 C. Ayoub and Lost Array 题目大意:一个长度为n的数组,数组的元素都在[L,R]之间,并且数组全 ...

随机推荐

  1. .net core 中间件实战

    1.新建一个ASP.NET Core Web Application项目,选择空模板. 2.新建一个类RequestIPMiddleware.cs using Microsoft.AspNetCore ...

  2. mysql 使用 GROUP BY 时报错 ERROR 1055 (42000)

    解决方法1:SET sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));这种修改只是暂时性的,还是在 my.ini 文件中的sq ...

  3. atnodes命令使用方法

    一条命令可以同时执行多台机器,结果会输出列表. atnodes -L 'grep -c "查询订单列表,userId=bing.wang03" /home/w/www/order- ...

  4. centos7 设置系统默认启动的界面

    系统默认 以某种方式启动 使用systemd创建符号链接指向默认运行级别. 修改方法为:在root下 1.首先删除已经存在的符号链接rm /etc/systemd/system/default.tar ...

  5. Permanent Space 和 Heap Space

      JVM堆内存 JVM堆内存分为2块:Permanent Space 和 Heap Space. Permanent 即 持久代(Permanent Generation),主要存放的是Java类定 ...

  6. 怎样让scrollview滚动到底部?

    - (void)scrollsToBottomAnimated:(BOOL)animated { CGFloat offset = self.tableView.contentSize.height ...

  7. IntelliJ IDEA 调试技巧

    程序员的工作内容,有不少的时间是用在调试代码上.可以说不是在调试代码,就是即将调试代码. 掌握调试代码的一些技巧,在使用IDE提供的debugger时会快速定位问题的方式. 1.多线程调试 在多线程应 ...

  8. OS与Internet

    1 操作系统 操作系统(Operating System,简称OS)是管理和控制计算机硬件与软件资源的计算机程序,是直接运行在“裸机”上的最基本的系统软件,任何其他软件都必须在操作系统的支持下才能运行 ...

  9. spring-AOP之通知和顾问

    通知和顾问都是切面的实现形式,其中通知可以完成对目标对象方法简单的织入功能. 而顾问包装了通知,可以让我们对通知实现更加精细化的管理,让我们可以指定具体的切入点. 通知分为前置通知,环绕通知及后置通知 ...

  10. 最适合入门的Laravel中级教程(三)表单验证

    做开发有个原则是永远不能信任用户输入的数据: 即便前端已经做了验证: 在后端 php 也必须要再次验证: laravel 为表单验证提供了强大且简单的方案: 创建示例路由: routes/web.ph ...