Codeforces Round #539 (Div. 2) D 思维
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 思维的更多相关文章
- 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 ...
- Codeforces Round #539 (Div. 2)
Codeforces Round #539 (Div. 2) A - Sasha and His Trip #include<bits/stdc++.h> #include<iost ...
- Codeforces Round #539 (Div. 2) 题解
Codeforces Round #539 (Div. 2) 题目链接:https://codeforces.com/contest/1113 A. Sasha and His Trip 题意: n个 ...
- 【CF1256】Codeforces Round #598 (Div. 3) 【思维+贪心+DP】
https://codeforces.com/contest/1256 A:Payment Without Change[思维] 题意:给你a个价值n的物品和b个价值1的物品,问是否存在取物方案使得价 ...
- Codeforces Round #143 (Div. 2) (ABCD 思维场)
题目连链接:http://codeforces.com/contest/231 A. Team time limit per test:2 seconds memory limit per test: ...
- 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 ...
- 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 ...
- Codeforces Round #533 (Div. 2) C.思维dp D. 多源BFS
题目链接:https://codeforces.com/contest/1105 C. Ayoub and Lost Array 题目大意:一个长度为n的数组,数组的元素都在[L,R]之间,并且数组全 ...
随机推荐
- Action Form的过程
1.读取配置(初始化ModuleConfig对象) Struts框架总控制器(ActionServlet)是一个Servlet, 在web.xml中配置成自动启动的Servlet. 读取配置文件(st ...
- 【亲测显式等待】Selenium:元素等待的4种方法
Selenium:元素等待的4种方法 1.使用Thread.sleep(),这是最笨的方法,但有时候也能用到而且很实用. 2.隐式等待,隐性等待是指当要查找元素,而这个元素没有马上出现时,告诉We ...
- element-ui input输入框回车事件
<el-input maxlength="30" v-model="answerInput" @keyup.enter.native="addA ...
- Laravel线上布暑到linux的问题汇总
1.直接报403错误 ,配置文件中增加: location / { try_files $uri $uri/ /index.php?$query_string; } 同时根目录不是指到项目名,而是指到 ...
- MaC 修改MySQL密码
1.苹果->系统偏好设置->最下边点mysql 在弹出页面中 关闭mysql服务(点击stop mysql server) 2.进入终端输入:cd /usr/local/mysql/bin ...
- 62.纯 CSS 创作一只蒸锅(感觉不好看呀)
原文地址:https://segmentfault.com/a/1190000015389338 HTML code: <!-- steamer: 蒸锅: lid: 盖子: pot: 锅 --& ...
- ORACLE日常操作手册
转发自:http://blog.csdn.net/lichangzai/article/details/7955766 以前为开发人员编写的oracle基础操作手册,都基本的oracle操作和SQL语 ...
- PHP和Redis实现在高并发下的抢购及秒杀功能示例详解
抢购.秒杀是平常很常见的场景,面试的时候面试官也经常会问到,比如问你淘宝中的抢购秒杀是怎么实现的等等. 抢购.秒杀实现很简单,但是有些问题需要解决,主要针对两个问题: 一.高并发对数据库产生的压力二. ...
- R语言-优化作图
par()函数:用来设置画图参数的函数par()的作用直到画板被关闭为止 1.设置背景颜色 #设置背景颜色 > par(bg="gray") #设置画板背景色 > pl ...
- k8s之配置flanneld网络
Flannel是Overlay网络的一种,也是将源数据包封装在另一种网络包里面进行路由转发和通信,目前已经支持UDP.VXLAN.AWS VPC和GCE路由等数据转发方式. Flannel通过给每台宿 ...