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求 ...
随机推荐
- lettcode-102:Binary Tree Level Order Traversal (Java)
Binary Tree Level Order Traversal 二叉树的层序遍历 两种方式: 1.用两个queue交替表示每一层的节点 2.用两个node,一个表示当前层的最后一个节点,一个表示下 ...
- Oracle的登录操作
在完美的启动Oracle数据库之后就可以登录数据库了: 1. 首先登录时使用的用户名默认是“SYSTEM”密码是你安装的时候自行设置的. 登录使用的命令是“sqlplus / as sysdba”之后 ...
- php smarty foreach循环注意
在template中,要注意{foreach from=$arr item=value}其中的value不需要$美元符号
- Linux中与DNS相关的内容
Linux中与DNS有关的三个东西: 1. 主机名 2. DNS服务器 3. Host文件 Linux中和DNS有关的三个文件: 1. /etc/hostname 2. /etc/resolv.con ...
- UVA 10273 Eat or Not to Eat?
这个题目一直以为是要用图论知识来做,可是一点建图的思绪都没有,后来知道暴力便可破之.由于牛的产奶周期最大为10,1.2.3.....10的最小公倍数是MT = 2520,所以把MT作为最大的周期,然后 ...
- UVA 10608 Friends
题目大意:共有n个人,m对人为已知的朋友关系,而且这种关系具有传递性,也就是A与B,B与C是朋友,可以确定A与C是朋友,求一个人数最多的朋友团体. bfs就可以了,遇到未访问的结点,加入队列并且朋人数 ...
- VC 为静态控件添加事件(修改ID号以后添加事件)
操作系统:Windows 7软件环境:Visual C++ 2008 SP1本次目的:为静态控件添加事件,如:STATIC.Picture Control等等 有时候我们找到一个图片,为对话框背景添加 ...
- Linux下归档与压缩工具笔记
tar具体使用笔记 归档工具 tar 语法 功能 选项 常见搭配 压缩工具 bzip2 工具 使用方法 gzip 工具 zip 工具 归档工具 tar tar是一个开源的Linux/Unix中最广泛使 ...
- 【转】Android 4.4源码下载与编译
原文网址:http://www.cnblogs.com/zhx831/p/3550830.html 这篇文章记录了我下载源码和编译的全过程, 全过程参考Android官方文档 1. 下载Android ...
- jQuery与XML
jQuery与XML 快而强的遍历系统,华丽丽的选择器语法,这或许是jQuery 那么流行的原因.当然它还有详尽的文档.它主要是用来处理HTML的,但在这里妳会看到如何应用到XML. 使用jQuery ...