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. 知识点:Mysql 基本用法之存储过程

    存储过程 一. 介绍 存储过程包含了一系列可执行的sql语句,存储过程存放于MySQL中,通过调用它的名字可以执行其内部的一堆sql 使用存储过程的优点: 用于替代程序写的SQL语句,实现程序与sql ...

  2. Northwind数据库练习及参考答案

    --查询订购日期在1996年7月1日至1996年7月15日之间的订单的订购日期.订单ID.客户ID和雇员ID等字段的值 Create View Orderquery as Select OrderDa ...

  3. vuex状态管理-数据改变不刷新

    困惑: 在页面初始化的时候,我提交到vuex状态管理,然后在获取的时候获取不到,我找到了出错的地点,并进行了修改,然后可以获取到状态 但是不知道原因? 定义了如下的state const state ...

  4. syslog-ng日志收集分析服务搭建及配置

    syslog-ng日志收集分析服务搭建及配置:1.网上下载eventlog_0.2.12.tar.gz.libol-0.3.18.tar.gz.syslog-ng_3.3.5.tar.gz三个软件: ...

  5. Android 开发 AlarmManager 定时器

    介绍 AlarmManager是Android中常用的一种系统级别的提示服务,在特定的时刻为我们广播一个指定的Intent.简单的说就是我们设定一个时间,然后在该时间到来时,AlarmManager为 ...

  6. js跨域传值,兼容ie8以上

    js跨域传值,兼容ie8以上 事先说明,此方法并不支持ie8,如果想要支持ie8的话,需要用这种思路(来自微软): if (window.addEventListener) { window.addE ...

  7. python至winreg模块

    _winreg模块在python3中已经改名了 https://blog.csdn.net/zhangxiaoyang0/article/details/72236305?fps=1&loca ...

  8. Python3执行DOS命令并截取其输出到一个列表字符串,同时写入一个文件

    #执行DOS命令并截取其输出到一个列表字符串,同时写入一个文件#这个功能很有用listing=os.popen('ipconfig').readlines()for i in listing: pri ...

  9. 应用脚手架创建一个React项目

    安装脚手架,这里会自动安装到你的nodejs里面 npm install create-react-app -g 进入创建目录 我这里创建一个为 react03的项目,等待下载..... create ...

  10. javascript中正则表达式中的 match,exec,test,replace 之我理解

    这个正则 ($&) 的语法: https://msdn.microsoft.com/library/3k9c4a32(v=vs.94).aspx 在ECMAScript中对这几个的说明: ma ...