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求 ...
随机推荐
- 如何使一个input文本框随其中内容而变化长度(转)
第一: <input type="text" onkeydown="this.onkeyup();" onkeyup="this.size=(t ...
- JSON漫谈
JSON: JavaScript Object Notation(JavaScript 对象表示法),JSON 是存储和交换文本信息的语法.类似 XML.JSON 比 XML 更小.更快,更易解析. ...
- Spatial Pyramid Matching 小结
Spatial Pyramid Matching 小结 稀疏编码系列: (一)----Spatial Pyramid 小结 (二)----图像的稀疏表示——ScSPM和LLC的总结 (三)----理解 ...
- pmtest1.asm pmtest2.asm pmtest5.asm 这几个比较重要.
读代码时注意Label后面的文字:desc表示是描述符,seg表示是段 pmtest1.asm 主要讲进入保护模式 http://www.cnblogs.com/wanghj-dz/archive/2 ...
- [状压dp]POJ2686 Traveling by Stagecoach
题意: m个城市, n张车票, 每张车票$t_i$匹马, 每张车票可以沿某条道路到相邻城市, 花费是路的长度除以马的数量. 求a到b的最小花费, 不能到达输出Impossible $1\le n\le ...
- HDU 5008 Boring String Problem
题意:给定一个串长度<=1e5,将其所有的不同的字串按照字典序排序,然后q个询问,每次询问字典序第k小的的起始坐标,并且起始坐标尽量小. 分析: 一开始看错题意,没有意识到是求不同的字串中第k小 ...
- FireMonkey vs. VCL (FMX的UI更灵活,图形效果更强,硬件加速,内嵌3D,使用浮点数更精确,跨平台,可使用Mida converter转换和TFireMonkeyContainer内嵌)
Frequently when I am talking about the VCL or FireMonkey I get some of these common questions: Is VC ...
- Android java.net.SocketException四大异常解决方案
java.net.SocketException如何才能更好的使用呢?这个就需要我们先要了解有关这个语言的相关问题.希望大家有所帮助.那么我们就来看看有关java.net.SocketExceptio ...
- 解决MYSQL 8小时连接问题
之前在使用SSH开发项目的时候遇到了一个很奇怪的问题,部署到服务器上,运行一段时间后系统就崩溃了. 出现错误:org.hibernate.exception.JDBCConnectionExcepti ...
- C# SerializableDictionary序列化/反序列化
说明:Dictionary对象本身不支持序列化和反序列化,需要定义一个继承自Dictionary, IXmlSerializable类的自定义类来实现该功能.感觉完全可以把这样的类封装到C#库中,很具 ...