第二届山东省ACM省赛回顾 Crack Mathmen(打表)
来源:互联网 发布:手机淘宝举报在哪里看 编辑:程序博客网 时间:2024/06/06 11:02
Crack Mathmen
题目链接:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2165
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?
输入
输出
示例输入
3259035703569703000010010010010011000000000001001001001001
示例输出
WorldNo SolutionNo Solution第一行3,代表三组数据,然后每组输入两行 第一行是 n 第二行是要破译的密码;把密码分成每三个数字一组,去破译例如第一组样例 590357035697030 把它每3个拆成一组,每组翻译成一个字符,第一行输入的 n=2,代表该字符asc码的几次方例如 590 = 87^2%997 , 'W的'asc码就是 87,, 所以第一个字母是 W,依次类推输出了 World;可以看出只要我们知道了asc码,我们就能求出 对应的字符,很容易想到打表,因为题目说翻译后的密码只包含大小写字母和数字,数组不用开很大就能储存;而 对于求幂取模,,直接套用快速幂模板就行了。 No Solution的情况: 1:没有对应的字符 2:对应的字符多于一个#include <stdio.h>#include <cmath>#include <cstring>#include <stdlib.h>typedef long long ll;const int maxn=1000000+10;char str[maxn];char test[maxn/3][5];char ar[1010];int signaa;ll pow_mod(ll x,ll n, ll mod) //快速幂模板{ll res=1;x=x%mod;while(n>0){if(n%2){res=res*x%mod;}x=x*x%mod;n/=2;}return res;}int main(){int n;scanf("%d",&n);int cas=0;while(n--){signaa=0;memset(ar,'\0',sizeof(ar));memset(str,'\0',sizeof(str));int t;scanf("%d",&t);getchar();int i;int res;for(int i=48;i<=122;i++){if((i>=48&&i<=57)||(i>=65&&i<=90)||(i>=97&&i<=122)){res=pow_mod(i,t,997);//输入了t之后,把求出的值储存到字符数组ar的坐标,把该位置的asc码转换成字符存到ac中if(ar[res]=='\0') //用来标记是否有重复的密码ar[res]=char(i);//把该位置的asc码转换成字符存到ac中else{signaa=1;//如果重复,标记变量变为1;break;}}}gets(str);int len=strlen(str);int k=0,s=0;for(int i=0;i<len;i++){if(i%3==0){k++;s=0;}test[k][s++]=str[i];//每三个字符存到另一个数组中,,当然也可以int res=(str[i]-'0')*100+(str[i+1]-'0')*10+str[i+2]-'0';更简单}if(signaa){printf("No Solution\n");continue;}else{for(int i=1;i<=k;i++){int res=atoi(test[i]);if(ar[res]!='\0')printf("%c",ar[res]);else{signaa=1;break;}}if(signaa){printf("No Solution\n");}elseprintf("\n");}}return 0;}
- 第二届山东省ACM省赛回顾 Crack Mathmen(打表)
- 山东省第二届ACM大学生程序设计竞赛 Crack Mathmen 打表 模拟
- sdut2165 Crack Mathmen (山东省第二届ACM省赛)
- SDUT 2165 Crack Mathmen(快速幂)山东省第二届ACM大学生程序设计竞赛
- [2011山东省第二届ACM大学生程序设计竞赛]——Crack Mathmen
- 山东省第二届ACM大学生程序设计竞赛——Crack Mathmen
- Sdut 2165 Crack Mathmen(数论)(山东省ACM第二届省赛E 题)
- 第二届山东ACM省赛 Crack Mathmen
- 山东省第二届ACM省赛 Mathmen
- sdut2165——Crack Mathmen(快速幂+打表)
- [2011山东省第二届ACM大学生程序设计竞赛]——Mathmen
- 山东省第二届ACM省赛 Binomial Coeffcients(组合数学)
- 山东省第二届 ACM 省赛 Simple Game (Nim+Bash)
- 山东省第二届ACM B题题解
- 山东省第二届ACM省赛 Identifiers
- 山东省第二届ACM省赛 I
- 山东省第二届ACM省赛 Simple Game
- 第八届山东省ACM省赛总结
- Caused by: org.xml.sax.SAXParseException; lineNumber: 28; columnNumber: 81;
- Visual Studio 2010打开工程非常慢一直卡在prepare solution窗口
- OpenCL之矩阵乘法实现
- sizeof精要
- servlet快速复习
- 第二届山东省ACM省赛回顾 Crack Mathmen(打表)
- 编程之美初赛第二场 扑克牌(四维dp,难)
- light oj 1248 - Dice (III)(期望)
- 多态
- Hopcroft-Karp 二分图HDU2389 Rain on your Parade
- lua gc和weaktable
- DP·数位DP(3)
- POJ 3281 Dining dinic
- C语言指针学习八