博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ2065 SETI
阅读量:6167 次
发布时间:2019-06-21

本文共 4150 字,大约阅读时间需要 13 分钟。

Description

For some years, quite a lot of work has been put into listening to electromagnetic radio signals received from space, in order to understand what civilizations in distant galaxies might be trying to tell us. One signal source that has been of particular interest to the scientists at Universit´e de Technologie Spatiale is the Nebula Stupidicus.

Recently, it was discovered that if each message is assumed to be transmitted as a sequence of integers a0,a1,...an1 the function f(k)=n1i=0aiki(modp) always evaluates to values 0<=f(k)<=26 for 1<=k<=n, provided that the correct value of p is used. n is of course the length of the transmitted message, and the ai denote integers such that 0<=ai<p. p is a prime number that is guaranteed to be larger than n as well as larger than 26. It is, however, known to never exceed 30000.
These relationships altogether have been considered too peculiar for being pure coincidences, which calls for further investigation.
The linguists at the faculty of Langues et Cultures Extraterrestres transcribe these messages to strings in the English alphabet to make the messages easier to handle while trying to interpret their meanings. The transcription procedure simply assigns the letters a..z to the values 1..26 that f(k) might evaluate to, such that 1=a, 2=b etc. The value 0 is transcribed to ‘*’ (an asterisk). While transcribing messages, the linguists simply loop from k=1 to n, and append the character corresponding to the value of f(k) at the end of the string.
The backward transcription procedure, has however, turned out to be too complex for the linguists to handle by themselves. You are therefore assigned the task of writing a program that converts a set of strings to their corresponding Extra Terrestial number sequences.

Input

On the first line of the input there is a single positive integer N, telling the number of test cases to follow. Each case consists of one line containing the value of p to use during the transcription of the string, followed by the actual string to be transcribed. The only allowed characters in the string are the lower case letters ‘a’..’z’ and ‘*’ (asterisk). No string will be longer than 70 characters.

Output

For each transcribed string, output a line with the corresponding list of integers, separated by space, with each integer given in the order of ascending values of i.

Sample Input

3

31 aaa
37 abc
29 hello*earth

Sample Output

1 0 0

0 1 0
8 13 9 13 4 27 18 10 12 24 15

Source

Northwestern Europe 2004

题目大意

给定一个素数p和一个字符串串str。令fi=Num(stri)Num(stri)表示当stri为*的时候为0stri为a-z的时候为stri'a'+1.接着得到nstri的长度)个方程组,每个方程格式为

(k0×a1+k1×a2++kn1×an)modp=fkmodp(1kn)
ai为未知量,让我们解这个方程组。

思路

将上面的方程组化成矩阵的形式就是:

1020n01121n11n12n1nn1f1f2fn
首先知道同余方程组可以互相相减,那么高斯消元的第一步(化成右上三角形式)与普通的高斯消元一样;
其次,高斯消元(代入)的话就是解形如
a×x=bmodp这样的同余方程,用逆元解即可。

代码

#include 
#include
#include
const int maxn=70;const int maxm=30000;int n,p,inv[maxm+1];long long gcd(long long a,long long b){ if(!b) { return a; } return gcd(b,a%b);}struct matrix{ long long a[maxn+1][maxn+2]; inline int gauss() { for(register int i=1; i
n) { return 1; } for(register int k=i; k<=n+1; ++k) { std::swap(a[j][k],a[i][k]); } } for(register int j=i+1; j<=n; ++j) { if(!a[j][i]) { continue; } if(a[j][i]%a[i][i]) { int d=gcd(a[j][i],a[i][i])*a[i][i]; for(register int k=i; k<=n+1; ++k) { a[j][k]=a[j][k]*d; } } int d=a[j][i]/a[i][i]%p; for(register int k=i; k<=n+1; ++k) { a[j][k]-=d*a[i][k]%p; a[j][k]=(a[j][k]%p+p)%p; } } } for(register int i=n; i>=1; --i) { a[i][n+1]=inv[a[i][i]]*a[i][n+1]%p; a[i][i]=1; for(register int j=1; j

转载于:https://www.cnblogs.com/Canopus-wym/p/10376245.html

你可能感兴趣的文章
hive 中的多列进行group by查询方法
查看>>
Cisco统一通信---视频部分
查看>>
nginx编译及参数详解
查看>>
VMware下PM魔术分区使用教程
查看>>
nslookup错误
查看>>
我的友情链接
查看>>
Supported plattforms
查看>>
做自己喜欢的事情
查看>>
CRM安装(二)
查看>>
Eclipse工具进行Spring开发时,Spring配置文件智能提示需要安装STS插件
查看>>
NSURLCache内存缓存
查看>>
jquery click嵌套 事件重复注册 多次执行的问题
查看>>
Dev GridControl导出
查看>>
开始翻译Windows Phone 8 Development for Absolute Beginners教程
查看>>
Python tablib模块
查看>>
站立会议02
查看>>
Windows和Linux如何使用Java代码实现关闭进程
查看>>
0428继承性 const static
查看>>
第一课:从一个简单的平方根运算学习平方根---【重温数学】
查看>>
NET反射系统
查看>>