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/ ...
随机推荐
- Kconfig详解-文件的基本要素 ***
当执行make menuconfig时会出现内核的配置界面,所有配置工具都是通过读取"arch/$(ARCH)Kconfig"文件来生成配置界面,这个文件就是所有配置的总入口,它会 ...
- BZOJ 5277 IQ题orz
思路: 首先我们注意到,对一个序列按分割点分开以后分别冒泡其实就相当于对整个序列进行冒泡.每一个元素都会对复杂度贡献1,除非一个元素两边的分割点都出现了.因此我们可以完全忽略快排的递归过程.只需考虑每 ...
- 【LeetCode】467. Unique Substrings in Wraparound String
Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz" ...
- ASP.NET 之正则表达式
转载自:http://www.regexlib.com/cheatsheet.htm?AspxAutoDetectCookieSupport=1 Metacharacters Defined MCha ...
- java环境搭建(及安装问题“No repository found containing”解决) 并创立第一个java程序
环境: java8 及 Eclipse java8 配置:http://jingyan.baidu.com/article/e2284b2b5967e7e2e7118d74.html Eclipse ...
- 【1】Jdk1.8中的HashMap实现原理
HashMap概述 HashMap是基于哈希表的Map接口的非同步实现.此实现提供所有可选的映射操作,并允许使用null值和null键.此类不保证映射的顺序,特别是它不保证该顺序恒久不变. 内部实现 ...
- C#入门经典 Chapter3 变量和表达式
3.1 C#基本语法 分号结束语句 花括号字符不需要附带分号 缩进 注释:/*....*/,//,/// 区分大小写 3.2 C#控制台应用程序的基本结构 namespace Chapter3 ...
- 【PostgreSQL-9.6.3】触发器实例
1. 创建一个触发器,表中的行在任何时候被插入或更新时,当前用户名和时间也会被标记在该行中.并且它会检查雇员的姓名以及薪水. --创建测试表 CREATE TABLE emp ( empname te ...
- JS——放大镜
放大镜: 1.比例系数要恒定:在系数为4的情况下,若原图是820*512,那么小图必须是205*128,放大镜若是50,原图显示区域必须200 2.计算鼠标在小图中的坐标 3.放大镜需要在鼠标中间位置 ...
- CSS——样式初始化
腾讯: body,ol,ul,h1,h2,h3,h4,h5,h6,p,th,td,dl,dd,form,fieldset,legend,input,textarea,select{margin:0;p ...