UOJ #74. 【UR #6】破解密码
2016-07-07 21:37
351 查看
事实这就是个hash
然后告诉你 hash值 求原字符串
注意h[i] 与 h[i+1]直接的关系
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int MAXN = 1e5+10;
#define LL long long
char out[MAXN];
int n,p,h[MAXN];
int power(int x,int y)
{
if(y==0) return 1;
int t=power(x,y/2);
t=(LL)t*t%p;
if(y&1) t=(LL)t*x%p;
return t;
}
int main()
{
cin >>n >>p;
for(int i=0;i<n;i++) scanf("%d",&h[i]);//cout<<"fd"<<endl;
int opt=(power(26,n)-1)%p;
h
=h[0];//cout<<opt<<endl;
if(opt!=0)
{//cout<<"faf";
for(int j=0;j<n;j++)
for(int i=0;i<26;i++)
if(h[j+1]==(((LL)h[j]*26-(LL)opt*i)%p+p)%p)
{
out[j]='a'+i;
break;
}
puts(out);//cout<<"fa";
}
else
{
for(int i=n-1;i>=0;i--)
{
out[i]=h[0]%26+'a';
h[0]/=26;
}
puts(out);
}
return 0;
}
然后告诉你 hash值 求原字符串
注意h[i] 与 h[i+1]直接的关系
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int MAXN = 1e5+10;
#define LL long long
char out[MAXN];
int n,p,h[MAXN];
int power(int x,int y)
{
if(y==0) return 1;
int t=power(x,y/2);
t=(LL)t*t%p;
if(y&1) t=(LL)t*x%p;
return t;
}
int main()
{
cin >>n >>p;
for(int i=0;i<n;i++) scanf("%d",&h[i]);//cout<<"fd"<<endl;
int opt=(power(26,n)-1)%p;
h
=h[0];//cout<<opt<<endl;
if(opt!=0)
{//cout<<"faf";
for(int j=0;j<n;j++)
for(int i=0;i<26;i++)
if(h[j+1]==(((LL)h[j]*26-(LL)opt*i)%p+p)%p)
{
out[j]='a'+i;
break;
}
puts(out);//cout<<"fa";
}
else
{
for(int i=n-1;i>=0;i--)
{
out[i]=h[0]%26+'a';
h[0]/=26;
}
puts(out);
}
return 0;
}
相关文章推荐
- solaris 镜像下的分区调整(将/var拆分为2个分区/var&/u01)
- EM算法
- Poj1384 Piggy-Bank
- c++中,用stringstream实现string的split
- procedure中的失足之-----跟变量翻脸
- session数据存入mysql
- 我的酷派大神1S 9976t的刷机过程
- 高斯模糊的实现方法
- 归并排序使用在c++STL实现
- 将Unity场景以Wavefront Obj格式导出
- Ant path 匹配原则 spring
- UOJ #31. 【UR #2】猪猪侠再战括号序列
- LoadRunner监控Tomcat的几种方法
- [置顶] spring整合cxf实现webservice发布
- IOS开发-单例模式安全写法
- 【数据库】临时表——基本知识
- 动态代理模式总结
- 能量项链(codevs 1154)
- vim:隆重推荐括号补全插件--auto-pairs
- Codevs (3657括号序列 )