H - Hash Code Hacker

题目链接

大意

hash的算法:
s [0]*31^( n -1) + s [1]*31^( n -2) + … + s [n -1]
给出一个k,让找出k个hash值相等的字符串,(只能由大小写英文字母构成)。

题解

这道题,毫无头绪,我又菜了。
好菜好菜

把它看成31进制,,,
前一位数-1,后一位数+31. 与原来的串相等。

代码

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <set>
#include <cstring>
#include <string>
#include <bitset>
#include <stdlib.h>
#include <time.h> 
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define st first
#define sd second
#define mkp make_pair
#define pb push_back
void wenjian(){
   freopen("hash.in","r",stdin);freopen("hash.out","w",stdout);}
ll gcd(ll a,ll b){
   return b == 0 ? a : gcd(b,a % b);}
ll qpow(ll a,ll b,ll mod){
   ll ans  = 1;while(b){
   if(b & 1)ans = ans * a % mod;a = a * a % mod;b >>= 1;}return ans;}
struct cmp{
   bool operator()(const pii & a, const pii & b){
   return a.second > b.second;}};


const int inf = 0x3f3f3f3f;

const int maxn = 1005;
char a[maxn];

int main()
{
   
	wenjian();
	int n;
	scanf("%d",&n);
	// printf("%d %d\n",'a','A');
	for (int i = 1; i <= 1000; i ++ )
		a[i] = 'B';
	printf("%s\n",a + 1);
	for (int  i= 1; i < n; i ++ )
	{
   
		a[i] -= 1;
		a[i + 1] += 31;
		printf("%s\n", a + 1);
		a[i] += 1;
		a[i + 1] -= 31;
	}
}

我觉得我要反思一下,因为我没有脑子了,