思维,,

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;
	}
}

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

全部评论

相关推荐

2025-12-10 19:36
湖北工业大学 Web前端
饿魔:看到在线简历了吧
点赞 评论 收藏
分享
2025-12-28 16:32
重庆邮电大学 Java
程序员花海:1.技能放最后,来面试默认你都会,技能没啥用 2.实习写的看起来没啥含金量,多读读部门文档,包装下 接LLM这个没含金量 也不要用重构这种 不会给实习生做的 3.抽奖这个还是Demo项目,实际在公司里面要考虑策略,满减,触发点,触发规则 库存 之类的,不是这个项目这么简单 4.教育背景提前,格式为 教育背景 实习 项目 技能 自我评价
简历被挂麻了,求建议
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务