日本搞逼视频_黄色一级片免费在线观看_色99久久_性明星video另类hd_欧美77_综合在线视频

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

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

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

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,' 主站蜘蛛池模板: 国产精品久久久久一区二区 | 日韩精品在线免费观看 | 在线免费福利 | 福利视频免费观看 | 免费一区 | 99久久免费国产 | 久久精品视频一区二区 | 精品一区二区三区免费 | 精品九九 | 国产成人精品综合 | 无码精品一区二区三区免费视频 | 国产伦精品一区二区三区高清版 | 91久久久久久久久久久久久 | 在线国产一区二区 | 欧美一区二区三区国产 | 日韩精品久久久久 | 爱情岛免费永久网站 | 精品国产髙清在线看国产毛片 | jizzz亚洲| 国产精品99久久久久久似苏梦涵 | 亚洲欧美精品一区 | 国产欧美日韩在线观看 | 欧美成人a| 插美女网站 | 99福利视频 | 99国产一区 | 亚洲日本va中文字幕久久 | 日本a在线 | 在线免费黄色 | 成人av一区二区三区 | 一区二视频 | 在线一区二区三区 | 久久999| 精品国产一区二区三区久久久 | 国产一区高清 | 欧美视频一区二区三区 | 日本欧美国产在线观看 | 狼人综合网 | 成年人免费视频观看 | 午夜午夜精品一区二区三区文 | 91亚洲成a人片在线观看www |