[Codeforces - Gym100801H (NEERC)] Hash Code Hacker (字符串构造)
来源:互联网 发布:犀牛软件 视角 加速器 编辑:程序博客网 时间:2024/05/20 14:41
Codeforces - Gym100801H (NEERC)
给定一个字符串hash,为
∑i=0len−1str[i]×31len−1−i
求K 个长度不超过 1000的字符串,使得他们的 hash值相等
其中每个 hash值是 32位有符号整数,K≤1000
构造题
先要把每个hash看作生成一个 31进制数
那么我随意生成一个字符串,
在高位减一,在低位加上 31,hash结果是一样的
所以我生成一个长度为 1000的字符串,然后逐位进行这样的操作
就正好能构造出 1000个hash值相等的字符串
然后输出前 K个即可
#pragma comment(linker, "/STACK:102400000,102400000")#include <cstdio>#include <iostream>#include <cstdlib>#include <cstring>#include <algorithm>#include <cmath>#include <cctype>#include <map>#include <set>#include <queue>#include <bitset>#include <string>#include <complex>using namespace std;typedef pair<int,int> Pii;typedef long long LL;typedef unsigned long long ULL;typedef double DBL;typedef long double LDBL;#define MST(a,b) memset(a,b,sizeof(a))#define CLR(a) MST(a,0)#define SQR(a) ((a)*(a))#define PCUT puts("\n----------")const int maxn=1e3+10;int N;char str[maxn];int main(){ #ifdef LOCAL freopen("in.txt", "r", stdin);// freopen("out.txt", "w", stdout); #endif #ifndef LOCAL freopen("hash.in", "r", stdin); freopen("hash.out", "w", stdout); #endif while(~scanf("%d", &N)) { for(int i=0; i<1000; i++) str[i] = 'X'; puts(str); for(int i=0; i<N-1; i++) { str[i] -= 1; str[i+1] += 31; puts(str); str[i] += 1; str[i+1] -= 31; } } return 0;}
0 0
- [Codeforces - Gym100801H (NEERC)] Hash Code Hacker (字符串构造)
- 【2015-2016 ACM-ICPC, NEERC, Northern Subregional Contest H】【字符串哈希 构造】Hash Code Hacker 构造有相同哈希值的不同字符串
- Hash Code Hacker
- [Codeforces - Gym10081D (NEERC)] Distribution in Metagonia (构造+数的拆分)
- Codeforces Gym 101190 NEERC 2016 B. Binary Code
- [构造] Codeforces Gym 101190 NEERC 16 C. Cactus Construction
- [构造] Codeforces Gym 100553 NEERC 14 E. Epic Win!
- [仙人掌同构 Hash] Codeforces Gym 100307 NEERC 13 C. Cactus Automorphisms
- codeforces #336 E. Marbles (字符串hash或者kmp匹配)
- Codeforces Gym 101164 K. Cutting (字符串 HASH)
- 10.21【Codeforces NEERC 胡玩记】
- [Trie树建图 2-SAT] Codeforces Gym 101190 NEERC 16 B. Binary Code
- The Hacker's Code
- CodeForces 113B Petr#(KMP + 字符串hash)
- codeforces 7D Palindrome Degree 字符串hash
- CodeForces 7D Palindrome Degree 字符串hash
- codeforces 166 Count Good Substrings 字符串hash
- Codeforces 113B Petr# 字符串hash
- canvas实战之一(画图,矩阵转换,定时)
- 抓取Java代码网络请求
- APUE - The implementations of sleep()
- 在测试spring mvc+junit4遇到的问题
- Android中hardware源码(android-5.0.2)
- [Codeforces - Gym100801H (NEERC)] Hash Code Hacker (字符串构造)
- web.xml
- String.split()应该怎么用?
- bzoj 2049: [Sdoi2008]Cave 洞穴勘测 link cut tree
- lvs+keepalived实现双机热备
- Codeforces #369(Div.2)B.Chris and Magic Square(矩阵找数)
- matlab的常量和变量&&运算符
- Java实现mysql增删改查--我的JDBC学习
- 第二周项目3-1 体验复杂度 两种算法的排序时间