POJ - 3541 - Given a string…
| Time Limit: 10000MS | Memory Limit: 65536K | |
| Total Submissions: 1819 | Accepted: 390 | |
| Case Time Limit: 2000MS | ||
Description
Peter’s Boss is now very upset. He said that Peter’s vision of the orthogonal sum of two strings is not collinear to the general pary line of RIGS. At least, it is very bad that the orthogonal sum of two strings in Peter’s vision can be different depending on a selected set of strings. But Boss decided to give Peter a last str…well, a chance.
Peter’s colleague Andrew invented another definition of orthogonal sum of two strings of equal length n, which depends only on the alphabet. The basic alphabet to define this operation consists only of zeros and ones. The orthogonal sum of two strings a ⊕ b is just a string c where ci = ai ⊕ bi (Si denotes i-th character of string S). Here ⊕ stands for exclusive OR operation which returns 0 for equal characters and 1 otherwise.
Now Peter must study properties of orthogonal closure of a given string S. The orthogonal closure of S (denoted S⊕) is a set of strings S(k) ⊕ S(l) for any 0 ≤ k, l ≤ n − 1, where n is the length of S, and S(k) denotes an operation of k-th circular shift of S — moving k last characters from the end of the string S to its beginning. For example, the second circular shift of abcde is deabc.
Given a string T, Peter’s task is to check whether it belongs to S⊕. Could you solve this task for him?
Input
The first line of the input file contains a given string T. The second line contains S. Both strings are of equal length in range from 1 to 5 000 characters. All characters in these strings are zeros or ones.
Output
If a given string belongs to S⊕, output “Yes”. Otherwise output “No”.
Sample Input
| #1 | 11111 10101 |
|---|---|
| #2 | 11110 10101 |
Sample Output
| #1 | No |
|---|---|
| #2 | Yes |
Source
#include <cstdio>
#include <cstring>
#include <algorithm>
#define MAX 100002
#define ll long long
#define XOR(x,y) ( x==y ? '0' : '1')
using namespace std; char s[MAX],t[MAX],e[MAX];
int next[MAX]; void get_next(char *p,int ls){
int k,i;
k=-;i=;
memset(next,-,sizeof(next));
while(i<=ls-){
if(k==- || p[i]==p[k]){ k++; i++; next[i]=k;}
else k=next[k];
}
} int kmp(int st,int ls,int lt){
int i,j;
i=;j=;
for(int k=;k<lt;k++) e[k]=XOR(s[st+k],t[k]);
e[lt]='\0';
get_next(e,lt);
while(i<ls && j<lt){
if(j==- || s[i]==e[j]){ i++; j++;}
else j=next[j];
}
if(j>=lt) return (i-lt+);
return -;
} int main(){
int f,lt,ls;
//freopen("data.txt","r",stdin);
while(scanf("%s",t)!=EOF){
scanf("%s",s);
lt=strlen(t);
ls=strlen(s);
for(int i=;i<ls;i++) s[i+ls]=s[i];
s[ls*]='\0';
f=-;
for(int i=;i<ls;i++){
f=kmp(i,ls*,lt);
if(f!=-) break;
}
if(f!=-) printf("Yes\n");
else printf("No\n");
}
return ;
}
/*3541*/
POJ - 3541 - Given a string…的更多相关文章
- POJ 2887:Big String(分块)
http://poj.org/problem?id=2887 题意:给出一个字符串,还有n个询问,第一种询问是给出一个位置p和字符c,要在位置p的前面插入c(如果p超过字符串长度,自动插在最后),第二 ...
- POJ 3336 Count the string (KMP+DP,好题)
参考连接: KMP+DP: http://www.cnblogs.com/yuelingzhi/archive/2011/08/03/2126346.html 另外给出一个没用dp做的:http:// ...
- poj 3729 Facer’s string
Facer’s string Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 2155 Accepted: 644 Des ...
- poj 2155 matrix 二维线段树 线段树套线段树
题意 一个$n*n$矩阵,初始全为0,每次翻转一个子矩阵,然后单点查找 题解 任意一种能维护二维平面的数据结构都可以 我这里写的是二维线段树,因为四分树的写法复杂度可能会退化,因此考虑用树套树实现二维 ...
- POJ 3376 Finding Palindromes EX-KMP+字典树
题意: 给你n个串串,每个串串可以选择和n个字符串拼接(可以自己和自己拼接),问有多少个拼接后的字符串是回文. 所有的串串长度不超过2e6: 题解: 这题由于是在POJ上,所以string也用不了,会 ...
- (转)ACM next_permutation函数
转自 stven_king的博客 这是一个求一个排序的下一个排列的函数,可以遍历全排列,要包含头文件<algorithm>下面是以前的笔记 (1) int 类型的next_permuta ...
- next_permutation函数
这是一个求一个排序的下一个排列的函数,可以遍历全排列,要包含头文件<algorithm>下面是以前的笔记 与之完全相反的函数还有prev_permutation (1) int 类 ...
- buaaoj230——next_permutation的应用
题目地址 简单的全排列输出,借用stl中的next_permutation就非常简单了. 关于next_permutation:(备忘,来源网络) /*这是一个求一个排序的下一个排列的函数,可以遍历全 ...
- 8-全排列next_permutation
C++中全排列函数next_permutation 用法 转载 2017年03月29日 14:38:25 1560 全排列参考了两位的博客 感谢! http://blog.sina.com.cn/s/ ...
随机推荐
- JSP-Runoob:JSP 日期处理
ylbtech-JSP-Runoob:JSP 日期处理 1.返回顶部 1. JSP 日期处理 使用JSP最重要的优势之一,就是可以使用所有Java API.本章将会详细地讲述Java中的Date类, ...
- bzoj1833
http://www.lydsy.com/JudgeOnline/problem.php?id=1833 2.5个小时就花在这上面了... 水到200题了...然并卵,天天做水题有什么前途... #i ...
- Webservice 的安全策略
摘自:http://www.cnblogs.com/shengel/archive/2008/11/20/1337723.html Webservice为作为方便的服务被用广大领域使用的同时, ...
- hadoop-Combiner作用用法
文章来源http://blog.csdn.net/ipolaris/article/details/8723782 reduce的输入每个key所对应的value将是一大串1,但处理的文本很多时,这一 ...
- python自动化学习笔记3-集合、函数、模块
文件操作 上次学习到文件的读写,为了高效的读写文件,我们可以用循环的方式,一行一行的进行读写操作,打开文件的方法是open的方法,打开文件执行完后还要进行关闭操作. 一般的文件流操作都包含缓冲机制,w ...
- SVD 学习笔记
本文主要学习了这篇博客:http://www.cnblogs.com/LeftNotEasy/archive/2011/01/19/svd-and-applications.html,将SVD讲的恨透 ...
- flask 中的模板语法 jinja2及render_template的深度用法
是时候开始写个前端了,Flask中默认的模板语言是Jinja2 现在我们来一步一步的学习一下 Jinja2 捎带手把 render_template 中留下的疑问解决一下 首先我们要在后端定义几个字符 ...
- 题解报告:hdu 1863 畅通工程
Problem Description 省政府“畅通工程”的目标是使全省任何两个村庄间都可以实现公路交通(但不一定有直接的公路相连,只要能间接通过公路可达即可).经过调查评估,得到的统计表中列出了有可 ...
- day03_12/13/2016_bean的管理之作用域与初始化时间
在Spring中,Bean有几种作用域: 1.singleton作用域 当一个bean的作用域设置为singleton,那么Spring IOC容器中只会存在一个共享的bean实例,并且所有对bean ...
- 关于static函数在类中的定义和使用
刷题的时候遇到了这样一个问题:平时经常使用 sort()函数, 对结构体进行排序, 但是在类中使用时会出现 这样的错误提示:“Solution::cmp”: 函数调用缺少参数列表:请使用“&S ...