Description

         Cyy likes something symmetrical, and Han Move likes something circular. Han Move gave you a circular string whose length is N, i.e. the i-th character of the string is the neighbor of the ( (i-1) mod N )-th character and ( (i+1) mod N )-th character.
         As Cyy likes something symmetrical, you want to find out whether this string can be symmetrical. There’s an operation for you to make the string symmetrical. This operation is called “disconnect”. You can use “disconnect” only once to break the link between any two neighbor characters, making the circular string into a linear string. If you can use “disconnect” to make this string into a palindrome, this string can be considered to be symmetrical.

Please tell Cyy whether this circular string is symmetrical.

Input

  1. The input file consists of multiple test cases.
  2. For each test case, theres only a string in a line to represent the circular string. The string only consists of lowercase characters. ( 1 <= N <= 65536 )
  3. Its guaranteed that the sum of N is not larger than 1000000.

Output

  1. For each test case, output Yes in a line if the circular string is symmetrical, output No otherwise.

Sample Input

  1. aaaaaa
  2. abcde
  3. ababab
  4. aaaaba
  5. aabbaa

Sample Output

  1. Yes
  2. No
  3. No
  4. No
  5. Yes

一句话题意:循环字符串能否断开形成回文串
循环的东西,很明显要直接复制一遍
回文串,很明显manacher

如果原串长度len为奇数,则找到的回文数长度m必须>=len且m为奇数

如果原串长度len为偶数,则找到的回文数长度m必须>=len且m为偶数

一开始总是超时,一直以为是判断输入结束不对,后来才发现是用了string,每次都用string生成!#a#b..,很耗时!

  1. #include<iostream>
  2. #include<stdio.h>
  3. #include<math.h>
  4. #include<stdlib.h>
  5. #include<string.h>
  6. #include<algorithm>
  7. using namespace std;
  8.  
  9. int p[];
  10. bool manacher(char* s,int len){
  11. int length=;
  12. int maxRight=;
  13. int mid=;
  14. int l=strlen(s);
  15. for(int i=;i<l;++i)
  16. {
  17. if(i<maxRight)
  18. p[i]=min(p[*mid-i],maxRight-i);
  19. else p[i]=;
  20.  
  21. while(s[i-p[i]]==s[i+p[i]]) p[i]++;
  22.  
  23. if(p[i]+i>maxRight)
  24. {
  25. maxRight=p[i]+i;
  26. mid=i;
  27. }
  28. length=p[i]-;
  29. if(len%==)
  30. {
  31. if(!(length<len||length%==))
  32. return true;
  33. }
  34. if(len%==)
  35. {
  36. if(!(length<len||length%==))
  37. return true;
  38. }
  39. }
  40. return false;
  41.  
  42. }
  43.  
  44. int main()
  45. {
  46. int len;
  47. char s[];
  48.  
  49. while(~scanf("%s",&s))
  50. {
  51. len=strlen(s);
  52. for(int i=len;i>=;--i)
  53. s[i+len]=s[i];
  54. // cout<<s<<endl;
  55. for(int i=*len;i>=;--i)
  56. {
  57. s[*i+]=s[i];
  58. s[*i+]='#';
  59. }
  60.  
  61. s[]='!';
  62. // cout<<s<<endl;
  63.  
  64. if(manacher(s,len)==true)
  65. cout<<"Yes"<<endl;
  66. else cout<<"No"<<endl;
  67. }
  68.  
  69. }
  1.  

武大OJ 622. Symmetrical的更多相关文章

  1. 武大OJ 574. K-th smallest

    Description Give you a number S of length n,you can choose a position and remove the number on it.Af ...

  2. 武大OJ 613. Count in Sama’s triangle

    Description Today, the math teacher taught Alice Hui Yang’s triangle. However, the teacher came up w ...

  3. 武大OJ 612. Catch the sheep

    Description Old Sama is a great and powerful magician in the word. One day, a little girl, Anny, tou ...

  4. 武大OJ 706.Farm

    Farmer John has a farm. Betsy, a famous cow, loves running in farmer John's land. The noise she made ...

  5. Online Judge(OJ)搭建(第一版)

    搭建 OJ 需要的知识(重要性排序): Java SE(Basic Knowledge, String, FileWriter, JavaCompiler, URLClassLoader, Secur ...

  6. [C#] 逆袭——自制日刷千题的AC自动机攻克HDU OJ

    前言 做过杭电.浙大或是北大等ACM题库的人一定对“刷题”不陌生,以杭电OJ为例:首先打开首页(http://acm.hdu.edu.cn/),然后登陆,接着找到“Online Exercise”下的 ...

  7. oj Rapid Typing

    import bs4 import requests import urllib2 import time import base64 session=requests.Session() respo ...

  8. 在线OJ实用技巧(转载)

    1.一般用C语言节约空间,要用C++库函数或STL时才用C++; cout.cin和printf.scanf最好不要混用. 2.有时候int型不够用,可以用long long或__int64型(两个下 ...

  9. OJ生成器(一)制作Online Judge前的准备和策划

    我这校区新的微机老师斗志昂扬,准备让我们这学校萎靡的信息技术竞赛重振雄风.然后有一次我半开玩笑地说建一个自己的OJ吧,老师也就鼓励我去做了. 开什么玩笑……!我可是马上要参加NOIP的人! 于是老师说 ...

随机推荐

  1. 题解报告:hdu 5695 Gym Class(拓扑排序)

    题目链接:acm.hdu.edu.cn/showproblem.php?pid=5695 Problem Description 众所周知,度度熊喜欢各类体育活动.今天,它终于当上了梦寐以求的体育课老 ...

  2. Android内存管理(14)*使用开源库LeakCanary检查内存泄漏

    1.简介 它是一个非常简单好用的内存泄漏检测工具库.可以轻松检测Activity,Fragment的内存泄漏.如果有内存泄漏,它会产生一个通知. 2.资料 官网: https://github.com ...

  3. Geoserver常见问题总结

    原文地址 :http://blog.csdn.net/mygisforum/article/details/8249093 http://www.cnblogs.com/wang985850293/p ...

  4. Java编程思想读书笔记_第6章

    如何创建一个包: 比如创建一个包名为com.huawei 则在一个目录下如(d:\java)创建目录com/huawei 然后在huawei目录下创建一个文件Assist.java package c ...

  5. servU服务器连接不上问题的解决

    在服务器上安装了servU64位版,建立了用户,设置了防火墙,正常启动. 但在客户端发出FTP://服务器IP 命令后,弹出输入用户名和密码的对话框,输入正确的用户名和密码后,却始终连接不上. ftp ...

  6. phpcms v9文章内容页调用上一篇下一篇的方法(转)

    phpcms v9文章内容页调用上一篇下一篇的方法如下,魔客吧(www.moke8.com)提示您直接摘取如下代码中的红色部分即可: 上一篇:{$previous_page[url]}" t ...

  7. 自学php【一】 任务:图片上传即时可见

    工作已经快2周了,头儿给派了个任务做个企业站!这几天正在紧锣密鼓的作战中!等忙完了这个活!写下自己的学习心得体会!与看到文章的您一起分享! 在这里记录每次遇到的难题,如何解决的! 今天要做的功能就是实 ...

  8. Intel Processor Exception Handling

    当一个进程的行为超出预期时,系统将把它kill掉. On Intel IA-32 and Intel 64 architecture processors, each architecturally- ...

  9. CAD绘制一个单行文字(com接口VB语言)

    主要用到函数说明: _DMxDrawX::DrawText 绘制一个单行文字.详细说明如下: 参数 说明 DOUBLE dPosX >文字的位置的X坐标 DOUBLE dPosY 文字的位置的Y ...

  10. IDEA中springboot项目打包成jar

      springboot的打包方式有很多种.有打成war的,有打成jar的,也有直接提交到github,通过jekins进行打包部署的.这里主要介绍如何打成jar进行部署.不推荐用war,因为spri ...