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/ ...
随机推荐
- 织梦dedecms标签大全总结
织梦dedecms标签大全总结,同时还建议多参考dede默认模板,织梦默认模板上的标签还是很有参考价值的. dedecms系统参数全局标签,在后台系统设置里可以看到这个参数 网站名称:{dede:gl ...
- [App Store Connect帮助]一、 App Store Connect 使用入门(1)App Store Connect 工作流程
您使用 App Store Connect 提交并管理您在 App Store 中销售的 App,使用 TestFlight 分发您 App 的 Beta 版本,接受法律协议,输入您的税务和银行业务信 ...
- 微信小程序上传多张图片,及php后台处理
微信小程序上传多张图片,级小程序页面布局直接来代码index.wxml <view class='body' style='width:{{windowWidth}}px;height:{{wi ...
- MVC系列学习(七)-模板页
1.新建一个MVC项目,选择基本 2.查看文件 看到VS为我们生成了一些东西 布局页面,Layout 指定了模板页 3.开始实例 首先控制器中的代码如下: 视图中代码如下: 1.在/Views/_Vi ...
- ios数据的基本类型和流程控制
swift的声明变量方式和js是类似的.基本类型基本都和java的差不多,多了字符类型. let:用于声明常量: var:用于声明变量: 基本类型有:double,float,Int(数字类型):bo ...
- [Codeforces]Codeforces Round #489 (Div. 2)
Nastya and an Array 输出有几种不同的数字 #pragma comment(linker, "/STACK:102400000,102400000") #ifnd ...
- nginx下如何配置 ssl证书?腾讯云ssl证书为例!
nginx下如何配置 ssl证书?腾讯云ssl证书为例! 目前为止,https已经成为一种趋势,想要开启https就需要ssl证书. 首先,为域名注册ssl证书. 腾讯云注册地址:https://cl ...
- Puppeteer——自动化脚本设计
我被分配了一个繁琐的任务,就是要给100个相同的站点做同样的配置.曾经就有做过相同的事,那时还不会写脚本,全靠手动配置.机械的配置了两天的时间,身体感觉被掏空.所以这次我决定还是写一个脚本自动的进行配 ...
- 新浪云虚拟机ftp链接显示失败问题
新浪云虚拟机ftp链接显示失败问题 测试是在局域网遇到的 域名解析可以ping有字节回复 账号密码也没有错误,但是链接一直出现 连接失败 拒接连接等问题 解决办法: 其实是局域网内的问题,这 ...
- 【技术累积】【点】【java】【27】@JSONField
@JSONField 该注解隶属于阿里fastjson,方便fastjson处理对象时的一些操作 源码 @Retention(RetentionPolicy.RUNTIME) @Target({ El ...