好玩的东西
  • 板块灌水区
  • 楼主Lydic
  • 当前回复9
  • 已保存回复9
  • 发布时间2024/9/30 11:08
  • 上次更新2024/9/30 15:43:14
查看原帖
好玩的东西
1426488
Lydic楼主2024/9/30 11:08

众所周知 mt19937 rnd(x) 是一个随机类。

所以我们可以利用这个来做一个字符串转化程序。

如下,可以找到一个字符串对应的种子:

#include <bits/stdc++.h>
#define int long long	
using namespace std;
inline int read()
{
	int w=1,s=0;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')w=-1;ch=getchar();}
	while(isdigit(ch)){s=s*10+(ch-'0');ch=getchar();}
	return w*s;
}
const int mod=998244353;
const int maxn=2e6+10;
const int inf=1e9+7;
int change(int len,string s)
{
	for(int x=1;x<=3e7;x++)
	{
		mt19937 rnd(x);
		string ss;
		for(int i=1;i<=len;i++)ss=ss+char(rnd()%26+'a');
		if(s==ss)return x;
	}
}
string put(int len,int seed)
{
	mt19937 rnd(seed);
	string s;
	for(int i=1;i<=len;i++)s=s+char(rnd()%26+'a');
	return s;
}
signed main()
{
	string s="hi";
	int n=s.size();
	int seed=change(n,s);
	cout<<seed<<' '<<put(n,seed);
	return 0;
}
2024/9/30 11:08
加载中...