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. VRay(一)材质基础

    专业术语 漫反射(Diffuse reflection)高光反射(Specular reflection)折射(Refraction)菲涅耳反射(Fresnel reflection)次表面散射(Su ...

  2. springmvc的简单使用以及ssm框架的整合

    Spring web mvc是基于servlet的一个表现层框架 首先创建一个简单的web工程了解它的使用 web.xml的配置 <?xml version="1.0" en ...

  3. 实验一:通过bridge-utils工具创建网桥并实现网络连接

    实验名称: 通过bridge-utils工具创建网桥并实现网络连接 实验环境: 实验要求: 安装bridge-utils工具,创建网桥br0,通过brctl命令,为网桥配置IP地址192.168.23 ...

  4. js 常用代码片段

    一.预加载图像 如果你的网页中需要使用大量初始不可见的(例如,悬停的)图像,那么可以预加载这些图像. function preloadImages(){ for(var i=0;i<argume ...

  5. LeetCode contest-95[876,877,👁878]

    876. Middle of the Linked List first submission # Definition for singly-linked list. # class ListNod ...

  6. npm下载安装文件太慢..修改这个就好了..治好多年的便秘..真香预警

    修改 npm 的安装目录下的 npmrc文件 增加一条 registry=http://registry.cnpmjs.org 将原来的https改成下面的http $ npm config set ...

  7. 学习笔记:FIS3

    http://fis.baidu.com/ FIS3官网 [配环境]: 1.先要安装node.js https://nodejs.org/en/ NODE.js官网(下载这个,下载后运行:  http ...

  8. 新部署tomcat,An error occurred at line: [1] index_jsp.java

    环境: centos6.5 32位 oracle jdk 1.8 tomcat 7 问题: yum install tomcat后,返回如下错误: [root@centos]~# curl -v ht ...

  9. jquery.cookie用法及其注意点

    jquery.cookie是一个轻量级的cookie插件,由于已被封装好,可拿来即用. 基本的创建.读取.删除见另一篇文章 浅谈localStorage.sessionStorage 与cookie  ...

  10. Itellj Idea使用技巧

    模板设置: 类模板:File–>Settings–>Editor–>File and Code Templates–>Includes–>File Header 输入缩写 ...