sdut 2165:Crack Mathmen(第二届山东省省赛原题,数论)
Crack Mathmen
Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^
题目描述
For example, if they choose n = 2 and the message is "World" (without quotation marks), they encode the message like this:
1. the first character is 'W', and it's ASCII code is 87. Then f(′W′) = 87^2 mod 997 = 590.
2. the second character is 'o', and it's ASCII code is 111. Then f(′o′) = 111^2 mod 997 = 357.
3. the third character is 'r', and it's ASCII code is 114. Then f(′r′) = 114^2 mod 997 = 35. Since 10 <= f(′r′) < 100, they add a 0 in front and make it 035.
4. the forth character is 'l', and it's ASCII code is 108. Then f(′l′) = 108^2 mod 997 = 697.
5. the fifth character is 'd', and it's ASCII code is 100. Then f(′d′) = 100^2 mod 997 = 30. Since 10 <= f(′d′) < 100, they add a 0 in front and make it 030.
6. Hence, the encrypted message is "590357035697030".
One day, an encrypted message a mathman sent was intercepted by the human being. As the cleverest one, could you find out what the plain text (i.e., the message before encryption) was?
输入
输出
示例输入
3
2
590357035697030
0
001001001001001
1000000000
001001001001001
示例输出
World
No Solution
No Solution
提示
来源
#include <stdio.h>
#include <iostream>
#include <string.h>
using namespace std;
char a[];
char b[];
char map[]; //映射
int GetM(int t,int n) //快速幂求模
{
int ans = ;
while(n){
if(n & )
ans = (ans*t)%;
t=t*t%;
n>>=;
}
return ans;
}
bool GetMap(int n) //产生映射表
{
int c;
for(c=;c<=;c++){
int t = GetM(c,n);
if(map[t]!='\0') //该值已有对应的字母
return false;
map[t] = char(c);
}
return true;
}
int main()
{
int T;
scanf("%d",&T);
while(T--){
int i,n,len = ;
scanf("%d",&n);
scanf("%s",a);
memset(map,'\0',sizeof(map)); //初始化映射
if(!GetMap(n)){ //产生映射.如果失败,输出提示,退出本次循环
printf("No Solution\n");
continue;
}
//没有冲突,产生映射成功,根据映射表解码
int t = ;
int Len = strlen(a);
for(i=;i<Len;i+=){
t = (a[i]-'')* + (a[i+]-'')* + (a[i+]-'');
if(map[t]=='\0') //没有对应的映射
break;
b[len++] = map[t];
}
if(i<Len) //提前跳出
printf("No Solution\n");
else{
b[len] = '\0';
cout<<b<<endl;
}
}
return ;
}
Freecode : www.cnblogs.com/yym2013
sdut 2165:Crack Mathmen(第二届山东省省赛原题,数论)的更多相关文章
- sdut 2163:Identifiers(第二届山东省省赛原题,水题)
Identifiers Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Identifier is an important c ...
- sdut 2162:The Android University ACM Team Selection Contest(第二届山东省省赛原题,模拟题)
The Android University ACM Team Selection Contest Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里 ...
- sdut 2152:Balloons(第一届山东省省赛原题,DFS搜索)
Balloons Time Limit: 1000MS Memory limit: 65536K 题目描述 Both Saya and Kudo like balloons. One day, the ...
- sdut 2153:Clockwise(第一届山东省省赛原题,计算几何+DP)
Clockwise Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Saya have a long necklace with ...
- sdut 2154:Shopping(第一届山东省省赛原题,水题)
Shopping Time Limit: 1000MS Memory limit: 65536K 题目描述 Saya and Kudo go shopping together.You can ass ...
- sdut 2159:Ivan comes again!(第一届山东省省赛原题,STL之set使用)
Ivan comes again! Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 The Fairy Ivan gave Say ...
- sdut 2158:Hello World!(第一届山东省省赛原题,水题,穷举)
Hello World! Time Limit: 1000MS Memory limit: 65536K 题目描述 We know that Ivan gives Saya three problem ...
- sdut 2610:Boring Counting(第四届山东省省赛原题,划分树 + 二分)
Boring Counting Time Limit: 3000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 In this problem you a ...
- sdut 2411:Pixel density(第三届山东省省赛原题,字符串处理)
Pixel density Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Pixels per inch (PPI) or pi ...
随机推荐
- 初学JDBC,最简单示例
一.下载相应数据库驱动jar包,添加到项目中 二.注册驱动,数据库驱动只加入到classpath中是还不行的,还要在使用的时候注册一下,就像安装驱动软件,只拷贝到硬盘还不行,需要安装一下 Driver ...
- CentOS 设置网络(修改IP&修改网关&修改DNS)--update.14.08.15
自己电脑上装的虚拟机用桥接方式连接物理机,虚拟机重启后ip会发生变化,非常阻碍Xshell的连接和hosts指定的dns. 通过修改IP为static模式,保持IP不变. ============== ...
- iconv命令详解
功能] 对于给定文件把它的内容从一种编码转换成另一种编码. [描述] -f encoding :把字符从encoding编码开始转换. -t encoding :把字符转换到encoding编码. ...
- Nginx一致性哈希模块的Lua实现
Nginx一致性哈希模块的Lua重新实现 技术背景: 最近在工作中使用了nginx+redis 的架构,redis在后台做分布式存储,每个redis都存放不同的数据,这些数据都是某门户网站通过Hado ...
- apache mysql 正常启动 打开php网页延时
金山毒霸或者升级精灵修改了WINSOCK导致的.由于我电脑上也安装了金山毒霸,而且最近几天也升级过了,应该是同样的问题.于是搜索到恢复Winsock的方法: netsh winsock reset 使 ...
- c++实现加密和解密算法以及JNI技术的应用实例
#include "jiami.h" #include "jni.h" #include "com_test_start_CommonClassLoa ...
- linux挂载硬盘失败,报错!
剛把我的一顆硬碟 ( NTFS ) 接到 Ubuntu 桌機上. 然後要 mount 的時候,出現了下面的訊息: DBus error org.gtk.Private.RemoteVolumeMon ...
- 【整理】Angularjs 监听ng-repeat onfinishrender事件
http://stackoverflow.com/questions/15207788/calling-a-function-when-ng-repeat-has-finished http://ww ...
- POJ 2513 Colored Sticks
Colored Sticks Time Limit: 5000MS Memory Limit: 128000K Total Submissions: 28036 Accepted: 7428 ...
- Spring常用的接口和类(一)
一.ApplicationContextAware接口 当一个类需要获取ApplicationContext实例时,可以让该类实现ApplicationContextAware接口.代码展示如下: p ...