POJ#2065. SETI
题目描述
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.
输入格式
输出格式
样例输入输出
输入
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的更多相关文章
- POJ 2065 SETI(高斯消元)
题目链接:http://poj.org/problem?id=2065 题意:给出一个字符串S[1,n],字母a-z代表1到26,*代表0.我们用数组C[i]表示S[i]经过该变换得到的数字.给出一个 ...
- POJ 2065 SETI (高斯消元 取模)
题目链接 题意: 输入一个素数p和一个字符串s(只包含小写字母和‘*’),字符串中每个字符对应一个数字,'*'对应0,‘a’对应1,‘b’对应2.... 例如str[] = "abc&quo ...
- poj 2065 SETI 高斯消元
看题就知道要使用高斯消元求解! 代码如下: #include<iostream> #include<algorithm> #include<iomanip> #in ...
- POJ 2065 SETI [高斯消元同余]
题意自己看,反正是裸题... 普通高斯消元全换成模意义下行了 模模模! #include <iostream> #include <cstdio> #include <c ...
- 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 ...
- POJ 2065 SETI 高斯消元解线性同余方程
题意: 给出mod的大小,以及一个不大于70长度的字符串.每个字符代表一个数字,且为矩阵的增广列.系数矩阵如下 1^0 * a0 + 1^1 * a1 + ... + 1^(n-1) * an-1 = ...
- poj 2065 高斯消元(取模的方程组)
SETI Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 1735 Accepted: 1085 Description ...
- B - SETI POJ - 2065 (高斯消元)
题目链接:https://vjudge.net/contest/276374#problem/B 题目大意: 输入一个素数p和一个字符串s(只包含小写字母和‘*’),字符串中每个字符对应一个数字,'* ...
- POJ 2065 高斯消元求解问题
题目大意: f[k] = ∑a[i]*k^i % p 每一个f[k]的值就是字符串上第 k 个元素映射的值,*代表f[k] = 0 , 字母代表f[k] = str[i]-'a'+1 把每一个k^i求 ...
随机推荐
- jersey post提交到 ContainerRequestFilter 而HttpServletRequest获取不到数据(转)
jersey post提交到 ContainerRequestFilter 而HttpServletRequest获取不到数据 问题:在serverfilter request获取不到post提交的 ...
- leetcode-173:Binary Search Tree Iterator(Java)
Binary Search Tree Iterator Implement an iterator over a binary search tree (BST). Your iterator wil ...
- Linux数组array基础
Linux数组array基础[${a[*]}和$a的区别] Bash中,数组变量的赋值有两种方法: (1) name = (value1 ... valuen) 此时下标从0开始 (2) name[i ...
- 类模板 template<class T>
参考网址:http://c.biancheng.net/cpp/biancheng/view/213.html // demo3.cpp : 定义控制台应用程序的入口点. // #include &q ...
- JavaScript中的Function类型浅析
1. Function类型是js中引用类型之一,每个函数实际上都是Function类型的实例对象,具有自己的属性和方法.正因为函数式对象,所以函数名实际上也是一个指向函数对象的指针. 2. 常用的函数 ...
- BZOJ 1688: [Usaco2005 Open]Disease Manangement 疾病管理
Description Alas! A set of D (1 <= D <= 15) diseases (numbered 1..D) is running through the fa ...
- MemoryStream类
转自:http://www.cnblogs.com/kissdodog/archive/2013/01/20/2868864.html MemoryStream 是一个特例,MemoryStream中 ...
- android一个纠结的VFY错误
08-16 09:06:45.018: W/dalvikvm(2286): VFY: unable to resolve static method 3273: Lorg/slf4j/LoggerFa ...
- RTMP
实时消息传输协议 RTMP(Real Time Messaging Protocol) http://blog.csdn.net/defonds/article/details/17403225 译序 ...
- Altium查看所有快捷键,图文教程
方式一:依次打开“查看”>>"工作区面板">>“Help”>>“快捷方式”.即可. 英文版“快捷方式”为“shotcut” 方式二: 留意右下角 ...