多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > php開源 > php教程 > 第二屆山東省ACM省賽回顧 Crack Mathmen(打表)

第二屆山東省ACM省賽回顧 Crack Mathmen(打表)

來源:程序員人生   發布時間:2015-05-22 07:58:39 閱讀次數:3796次

Crack Mathmen

題目鏈接:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2165

Time Limit: 1000ms   Memory limit: 65536K  有疑問?點這里^_^

題目描寫

 Since mathmen take security very seriously, they communicate in encrypted messages. They cipher their texts in this way: for every characther c in the message, they replace c with f(c) = (the ASCII code of c)n mod 1997 if f(c) < 10, they put two preceding zeros in front of f(c) to make it a three digit number; if 10 <= f(c) < 100, they put one preceding zero in front of f(c) to make it a three digit number.

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?

輸入

 The input contains multiple test cases. The first line of the input contains a integer, indicating the number of test cases in the input. The first line of each test case contains a non-negative integer n (n <= 10^9). The second line of each test case contains a string of digits. The length of the string is at most 10^6.

輸出

 For each test case, output a line containing the plain text. If their are no or more than one possible plain text that can be encrypted as the input, then output "No Solution" (without quotation marks). Since mathmen use only alphebetical letters and digits, you can assume that no characters other than alphebetical letters and digits may occur in the plain text. Print a line between two test cases.

示例輸入

3
2
590357035697030
0
001001001001001
1000000000
001001001001001

示例輸出

World
No Solution
No Solution

第1行3,代表3組數據,然后每組輸入兩行 第1行是 n 第2行是要破譯的密碼;
把密碼分成每3個數字1組,去破譯

例如第1組樣例 590357035697030 把它每3個拆成1組,每組翻譯成1個字符,第1行輸入的 n=2,代表該字符asc碼的幾次方
例如 590 = 87^2%997  , 'W的'asc碼就是 87,, 所以第1個字母是 W,順次類推輸出了 World;
可以看出只要我們知道了asc碼,我們就可以求出 對應的字符,很容易想到打表,由于題目說翻譯后的密碼只包括大小寫字母和數字,數組不用開很大就可以貯存;
而 對求冪取模,,直接套用快速冪模板就好了。 No Solution的情況: 1:沒有對應的字符 2:對應的字符多于1個
#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,' 主站蜘蛛池模板: 久久精品一区二区免费看 | 免费观看无遮挡www的视频 | video18娇小粉嫩极品hd | 亚洲精品老司机综合影院 | 亚洲国产片| 日韩欧美一区二区三区不卡在线 | 欧美一级别 | ady久久 | 亚洲欧美中文字幕高清在线一 | 亚洲色图网站 | 成人欧美一级毛片免费观看 | 毛片毛片 | 91刘亦菲精品福利在线 | 国产精品jizz在线观看免费 | 色视频在线播放 | 亚洲线精品一区二区三区 | 国产亚洲精品精品国产亚洲综合 | 明星三级国产免费播放 | 久久久久亚洲日日精品 | 国产精品免费久久久久影院小说 | 中文字幕亚洲综合久久202 | 亚洲毛片视频 | 久久本网站受美利坚法律保护 | 日本免费一二区视频 | www.日本在线播放 | www.日本xxxx| 亚洲激情专区 | 亚洲精品国产一区二区在线 | 亚洲三级黄色片 | 亚洲人成在线播放网站 | 国产a不卡片精品免费观看 国产a国产片色老头 | 国产精品成人不卡在线观看 | 久草在线免费色站 | 日本日韩欧美 | 五月婷婷视频 | 日韩亚洲国产综合久久久 | 亚洲综合一区二区精品久久 | 欧美 亚洲 中文字幕 | 国产精品区一区二区三 | 久久xxx| 91中文字幕yellow字幕网 |