题目描述

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, ...an-1 the function f (k) = ∑0<=i<=n-1aiki (mod p) 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 30 000. 
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.

输入格式

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.

输出格式

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.

样例输入输出

输入

3
31 aaa
37 abc
29 hello*earth

输出

1 0 0
0 1 0
8 13 9 13 4 27 18 10 12 24 15 最近啦,再练高斯消元的题 , 算是比较简单的高斯消元 。
#include <iostream>
#include <cstring>
#include <cstdio>
//#include <cmath>
const long long inf = ;
const int Inf = << , maxn = ;
using namespace std ;
int t , p , n ;
char s[maxn] ;
long long a[maxn][maxn] , x[maxn] ;
bool free_x[maxn] ; void Init( )
{
scanf( "%d%s" , &p , s ) ;
n = strlen( s ) ;
for( int i = ; i < n ; ++i )
{
if( s[i] != '*' )
a[i][n] = ( s[i] - 'a' + ) % p ; a[i][] = ; // n -> he
for( int j = ; j < n ; ++j ) a[i][j] = (a[i][j-] * ( i + ) ) % p ; // xi shu
}
} long long int qabs( long long a )
{
if( a > ) return a ;
return -a ;
} void Solve( )
{
// max_r = 0 ;
int k , col ;
for( k = , col = ; k < n && col < n ; ++k , ++col )
{
int max_r = k ;
for( int i = k + ; i < n ; ++i )
if( qabs(a[i][col]) > qabs( a[max_r][col] ) ) max_r = i ; // find biggest and change
if( max_r != k ) //and change
{
for( int i = k ; i < n + ; ++i )
swap( a[k][i] , a[max_r][i] ) ;
}
for( int i = k + ; i < n ; ++i )
{
if( a[i][col] == ) continue ;
long long x1 = a[i][col] , x2 = a[k][col] ;
for( int j = col ; j < n + ; ++j )
{
a[i][j] = a[i][j] * x2 - a[k][j] * x1 ;
a[i][j] = ( ( a[i][j] % p + p ) % p + p ) ;
}
}
}
for( int i = k - ; i >= ; --i )
{
long long tmp = a[i][n] ;
for( int j = i + ; j < n ; ++j )
tmp = ( ( tmp - a[i][j] * x[j] ) % p + p ) % p ;
while( tmp % a[i][i] ) tmp += p ;
x[i] = ( ( tmp/ a[i][i] ) %p + p ) %p ;
}
} void Output( )
{
for( int i = ; i < n ; ++i )
{
if( i != ) printf( " " ) ;
printf( "%lld" , x[i] ) ;
} printf( "\n" ) ;
} int main( )
{
// freopen( "POJ#2065.in" , "r" , stdin ) ;
// freopen( "POJ#2065.out" , "w" , stdout ) ;
scanf( "%d" , &t ) ;
while( t-- )
{
memset( a , , sizeof(a) ) ;
memset( x , , sizeof(x) ) ;
memset( free_x , , sizeof(free_x) ) ;
Init( ) ;
Solve( ) ;
Output( ) ;
}
fclose( stdin ) ;
fclose( stdout ) ;
return ;
}

 

POJ#2065. SETI的更多相关文章

  1. POJ 2065 SETI(高斯消元)

    题目链接:http://poj.org/problem?id=2065 题意:给出一个字符串S[1,n],字母a-z代表1到26,*代表0.我们用数组C[i]表示S[i]经过该变换得到的数字.给出一个 ...

  2. POJ 2065 SETI (高斯消元 取模)

    题目链接 题意: 输入一个素数p和一个字符串s(只包含小写字母和‘*’),字符串中每个字符对应一个数字,'*'对应0,‘a’对应1,‘b’对应2.... 例如str[] = "abc&quo ...

  3. poj 2065 SETI 高斯消元

    看题就知道要使用高斯消元求解! 代码如下: #include<iostream> #include<algorithm> #include<iomanip> #in ...

  4. POJ 2065 SETI [高斯消元同余]

    题意自己看,反正是裸题... 普通高斯消元全换成模意义下行了 模模模! #include <iostream> #include <cstdio> #include <c ...

  5. POJ.2065.SETI(高斯消元 模线性方程组)

    题目链接 \(Description\) 求\(A_0,A_1,A_2,\cdots,A_{n-1}\),满足 \[A_0*1^0+A_1*1^1+\ldots+A_{n-1}*1^{n-1}\equ ...

  6. POJ 2065 SETI 高斯消元解线性同余方程

    题意: 给出mod的大小,以及一个不大于70长度的字符串.每个字符代表一个数字,且为矩阵的增广列.系数矩阵如下 1^0 * a0 + 1^1 * a1 + ... + 1^(n-1) * an-1 = ...

  7. poj 2065 高斯消元(取模的方程组)

    SETI Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 1735   Accepted: 1085 Description ...

  8. B - SETI POJ - 2065 (高斯消元)

    题目链接:https://vjudge.net/contest/276374#problem/B 题目大意: 输入一个素数p和一个字符串s(只包含小写字母和‘*’),字符串中每个字符对应一个数字,'* ...

  9. POJ 2065 高斯消元求解问题

    题目大意: f[k] = ∑a[i]*k^i % p 每一个f[k]的值就是字符串上第 k 个元素映射的值,*代表f[k] = 0 , 字母代表f[k] = str[i]-'a'+1 把每一个k^i求 ...

随机推荐

  1. Hyper-V中安装CentOS分辨率修改

    Hyper-V还是极好用的,不过对linux的支持优点问题, 比如默认情况,linux分辨率被锁定了,这里有一个比较简单的方法修改,针对CentOS grubby --update-kernel=AL ...

  2. IIS的Unicode漏洞攻击

    IIS有十多种常见漏洞,但利用得最多的莫过于Unicode解析错误漏洞.微软IIS 4.0/5.0在Unicode字符解码的实现中存在一个安全漏洞,用户可以远程通过IIS执行任意命令.当IIS打开文件 ...

  3. 【无聊放个模板系列】POJ2752 EXKMP

    #include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> #inc ...

  4. MongoDB实战指南(六):MongoDB复制集之复制集概述

    1. 复制集概述 数据库总是会遇到各种失败的场景,如网络连接断开.断电等,尽管journaling日志功能也提供了数据恢复的功能,但journaling通常是针对单个节点来说的,只能保证单节点数据的一 ...

  5. dropdownlist无刷新传值

    既然局部刷新,其实没有必要用服务器控件,即便用了服务器控件,也不应该将AutoPostBack="true" ,这将导致页面回发并刷新,因此去掉下拉框的该属性 至于局部改变div的 ...

  6. [wikioi]均分纸牌

    这是一道归为贪心题...http://wikioi.com/problem/1098/ 参考:http://www.cnblogs.com/taoziwel/articles/1859984.html ...

  7. money 和 smallmoney

    代表货币或货币值的数据类型. 数据类型 范围 存储 money -922,337,203,685,477.5808 到 922,337,203,685,477.5807 8 字节 smallmoney ...

  8. 优化 Android 线程和后台任务开发

    在 Android 开发中,你不应该做任何阻碍主线程的事情.但这究竟意味着什么呢?在这次海湾 Android 开发者大会讲座中,Ari Lacenski 认为对于长时间运行或潜在的复杂任务要特别小心. ...

  9. 【HDOJ】4267 A Simple Problem with Integers

    树状数组.Easy. /* 4267 */ #include <iostream> #include <string> #include <map> #includ ...

  10. 坑爹的libxml2 for mingw 编译

    按照官方的readerme.txt说法生成Makefile之后,你会发现编译时候需要创建几个文件夹. 还有就是因为宏定义问题,报错,需要在config.h中加入#define HAVE_STDINT_ ...