题目描述
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求 ...
随机推荐
-
iOS - HTTPS接口加密和身份认证
为什么要使用HTTPS代替HTTP HTTPS和HTTP的区别 https协议需要到CA申请证书,一般免费证书很少,需要交费. http是超文本传输协议,信息是明文传输,https则是具有安全性的SS ...
-
MVC 3 基本操作增加修改
在MVC中实现基本的增删改和传统的asp .net 程序有很大的不同,刚开始使用MVC还是有些不太适应,但是它的页面简洁也相当的不同,同时对服务器的访问性能上也有很大的提高.基于此,下面对我学习过程记 ...
-
basicAnimation移动图形
目的:采用CABasicAnimation 点击屏幕上的点来是实现图像的位置移动 并且位置能够不反弹 难点:1 通过动画的KeyPath找到layer的属性 2 通过NSValue将点包装成对象 ...
-
(转)iOS Wow体验 - 第二章 - iOS用户体验解析(2)
本文是<iOS Wow Factor:Apps and UX Design Techniques for iPhone and iPad>第二章译文精选的第二部分,其余章节将陆续放出.上一 ...
-
在opensips中记录通话记录
1.为acc表增加额外的字段记录主叫被叫进入mysql,选取opensips的数据库ALTER TABLE acc ADD from_uri VARCHAR(64) DEFAULT '' NOT NU ...
-
js中元素(图片)切换和隐藏显示问题
这个知识点其实也简单,(当然是在理清思路的情况下),在没预习的情况下听的还真是艰难,上课以来唯一的一次懵逼了一天,感觉乱乱的,全是新属性,所以今晚的我破天荒的熬夜敲代码,一定要弄懂! 现在就来梳理下头 ...
-
HDU 1520.Anniversary party 基础的树形dp
Anniversary party Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
-
检测到包降级: Microsoft.Extensions.Configuration.Abstractions 从 2.1.1 降 2.1.0
解决方法:工具-nuget管理包-程序管理控制台-选择 项目- 执行 -Install-Package Microsoft.Extensions.Configuration.Abstractions ...
-
MySQL导入数据错误error: 13 及解决办法
先说解决办法 将sql文件放到你的账号能够访问的地方!!! 因为我用的grid账号,所以只需要将sql放到 ~grid/ 或者 /tmp等grid能够访问的地方即可. Don't place the ...
-
20165310 预备作业3 Linux安装及学习
预备作业3 Linux安装及学习 安装虚拟机 之前在win7系统下通过EasyBCD安装过Ubuntu虚拟机,这次阅读<基于VirtualBox虚拟机安装Ubuntu图文教程>又学习到了一 ...