HDU5972RegularNumber(ShiftAnd算法bitset)
来源:fromnet 网络用户发布,如有版权联系网管删除 2018-10-12
题意
题目链接
第一行的(n)表示模式串长度为(n)
接下来(n)行,每行开头有一个整数(num)表示匹配串中该位置的字符可以在(num)个桅子花出现,接下来输入这(num)个位置
最后一行一个模式串
Sol
"It contains a set of test data"的意思原来是说只有一组测试数据
ShiftAnd算法,非常interesting,推荐一篇讲的非常好的blog
这题就是给出了(B)数组,然后暴力搞一下就行了。。
垃圾题目卡我读入卡我输出
#include#define chmax(a, b) (a = (a > b ? a : b))#define chmin(a, b) (a = (a < b ? a : b))#define LL long long//#define int long long using namespace std;const int MAXN = 5e6 + 10;inline int read() { int x = 0, f = 1; char c = getchar(); while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();} while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); return x * f;}int N;char s[MAXN], tmp = ' ';bitset<1001> b[11], ans;void solve() { for(int i = 0; i <= N; i++) b[i].reset(); ans.reset(); for(int i = 0; i < N; i++) { int num = read(); for(int j = 0; j < num; j++) b[read()].set(i); } gets(s); int L = strlen(s); for(int i = 0; i < L; i++) { ans <<= 1; ans.set(0); ans &= b[s[i] - '0']; if(ans[N - 1] == 1) swap(s[i + 1], tmp), puts(s + i - N + 1), swap(s[i + 1], tmp); }}main() { scanf("%d", &N); solve();}/*43 0 9 72 5 72 2 52 4 509755420524*/
查看评论 回复