HDU 5782 Cycle

Problem Description
Alice get two strings and the lengths are both N. Bored Alice wanna know whether all equal length prefix string of these two strings are CycleEqual. For example, "abc" and "bca" and "cab" are CycleEqual. So you need output N character, '0' is no, '1' is yes.
 

Input
The input contains multiple test cases.

For each test case, the first contains one string and the second line contains one string. The lengths of strings are both  N(1N10000) .
 

Output
For each test case, output N characters. For ith character, if prefix strings of first i character are CycleEqual, output '1', else output '0'.
 

Sample Input
  
  
abc cab aa aa
 

Sample Output
  
  
001 11

bitset瞎搞,想这种问题真废脑子啊,顺便知道了,数据范围是10000的很有可能就是这种套路。

#include<set>
#include<map>
#include<ctime>
#include<cmath>
#include<stack>
#include<queue>
#include<bitset>
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
#define rep(i,j,k) for (int i = j; i <= k; i++)
#define per(i,j,k) for (int i = j; i >= k; i--)
using namespace std;
typedef __int64 LL;
const int low(int x) { return x&-x; }
const double eps = 1e-8;
const int INF = 0x7FFFFFFF;
const int mod = 998244353;
const int N = 1e4;
int T, n;
char a[N], b[N];
bitset<N> as[N], bs[N], g[N], A[26], B[26], ans;

int main()
{
	g[0].reset();	g[0].set(0);
	rep(i, 1, N - 1) g[i] = g[i - 1] << 1, g[i].set(0);
	while (scanf("%s%s", a, b) != EOF)
	{
		n = strlen(a);
		rep(i, 0, 25) A[i].reset(), B[i].reset();
		rep(i, 0, n - 1)
		{
			A[a[i] - 'a'].set(i);
			B[b[i] - 'a'].set(i);
		}
		as[0] = A[b[0] - 'a'];
		rep(i, 1, n - 1) as[i] = as[i - 1] & (A[b[i] - 'a'] >> i);
		bs[0] = B[a[0] - 'a'];
		rep(i, 1, n - 1) bs[i] = bs[i - 1] & (B[a[i] - 'a'] >> i);
		ans.reset();
		rep(i, 0, n - 1)
		{
			int q = 0, r = n - i - 1;
			while (q <= r)
			{
				if (as[q + r >> 1][i]) q = (q + r >> 1) + 1;
				else r = (q + r >> 1) - 1;
			}
			if (i) ans |= (bs[i - 1] & g[q]) << i - 1;
			else if (q) ans |= g[q - 1];
		}
		rep(i, 0, n - 1) printf("%d", (int)ans[i]);
		putchar(10);
	}
	return 0;
}


评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值