POJ 1060:Modular multiplication of polynomials
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 4377 | Accepted: 1980 |
Description
0, (0 + 1) mod 2 = 1, (1 + 0) mod 2 = 1, and (1 + 1) mod 2 = 0. Hence, it is the same as the exclusive-or operation.
(x^6 + x^4 + x^2 + x + 1) + (x^7 + x + 1) = x^7 + x^6 + x^4 + x^2
Subtraction of two polynomials is done similarly. Since subtraction of coefficients is performed by subtraction modulo 2 which is also the exclusive-or operation, subtraction of polynomials is identical to addition of polynomials.
(x^6 + x^4 + x^2 + x + 1) - (x^7 + x + 1) = x^7 + x^6 + x^4 + x^2
Multiplication of two polynomials is done in the usual way (of course, addition of coefficients is performed by addition modulo 2).
(x^6 + x^4 + x^2 + x + 1) (x^7 + x + 1) = x^13 + x^11 + x^9 + x^8 + x^6 + x^5 + x^4 + x^3 + 1
Multiplication of two polynomials f(x) and g(x) modulo a polynomial h(x) is the remainder of f(x)g(x) divided by h(x).
(x^6 + x^4 + x^2 + x + 1) (x^7 + x + 1) modulo (x^8 + x^4 + x^3 + x + 1) = x^7 + x^6 + 1
The largest exponent of a polynomial is called its degree. For example, the degree of x^7 + x^6 + 1 is 7.
Given three polynomials f(x), g(x), and h(x), you are to write a program that computes f(x)g(x) modulo h(x).
We assume that the degrees of both f(x) and g(x) are less than the degree of h(x). The degree of a polynomial is less than 1000.
Since coefficients of a polynomial are 0 or 1, a polynomial can be represented by d+1 and a bit string of length d+1, where d is the degree of the polynomial and the bit string represents the coefficients of the polynomial. For example, x^7 + x^6 + 1 can be
represented by 8 1 1 0 0 0 0 0 1.
Input
above.
Output
Sample Input
2
7 1 0 1 0 1 1 1
8 1 0 0 0 0 0 1 1
9 1 0 0 0 1 1 0 1 1
10 1 1 0 1 0 0 1 0 0 1
12 1 1 0 1 0 0 1 1 0 0 1 0
15 1 0 1 0 1 1 0 1 1 1 1 1 0 0 1
Sample Output
8 1 1 0 0 0 0 0 1
14 1 1 0 1 1 0 0 1 1 1 0 1 0 0
Source
你 离 开 了 , 我 的 世 界 里 只 剩 下 雨 。 。 。
#include <iostream>
#include<string.h>
using namespace std;
int pd(int sum[],int ls,int h[],int lh)
{
if(ls>lh)return 1;
if(ls<lh)return -1;
if(ls==lh)
{
int i;
for(i=ls-1; i>=0; i--)
{
if(sum[i]&&!h[i])return 1;
if(!sum[i]&&h[i])return -1;
}
}
return 0;
}
int main()
{
int n;
cin>>n;
int c;
for(c=1; c<=n; c++)
{
int lf,lg,lh;
int f[1001],g[1001],h[1001];
int i;
cin>>lf;
for(i=lf-1; i>=0; i--)
cin>>f[i];
cin>>lg;
for(i=lg-1; i>=0; i--)
cin>>g[i];
cin>>lh;
for(i=lh-1; i>=0; i--)
cin>>h[i];
int sum[2001];
memset(sum,0,sizeof(sum));
int j;
for(i=0; i<lf; i++)
for(j=0; j<lg; j++)
sum[i+j]=sum[i+j]^(f[i]&g[j]);
int ls;
ls=lf+lg-1;
while(pd(sum,ls,h,lh)>=0)
{
int d=ls-lh;
for(i=0; i<lh; i++)
sum[i+d]=sum[i+d]^h[i];
while(ls&&!sum[ls-1])
--ls;
}
if(ls==0)ls=1;
cout<<ls<<" ";
for(i=ls-1; i>0; i--)
cout<<sum[i]<<" ";
cout<<sum[0]<<endl;
}
return 0;
}
POJ 1060:Modular multiplication of polynomials的更多相关文章
- POJ 1060 Modular multiplication of polynomials(多项式的加减乘除,除法转化成减法来求)
题意:给出f(x),g(x),h(x)的 (最高次幂+1)的值,以及它们的各项系数,求f(x)*g(x)/h(x)的余数. 这里多项式的系数只有1或0,因为题目要求:这里多项式的加减法是将系数相加/减 ...
- POJ1060 Modular multiplication of polynomials
题目来源:http://poj.org/problem?id=1060 题目大意: 考虑系数为0和1的多项式.两个多项式的加法可以通过把相应次数项的系数相加而实现.但此处我们用模2加法来计算系数之和. ...
- POJ1060 Modular multiplication of polynomials解题报告 (2011-12-09 20:27:53)
Modular multiplication of polynomials Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 3 ...
- UVALive 2323 Modular Multiplication of Polynomials(模拟)
这是一个相对简单的模拟,因为运算规则已经告诉了我们,并且比较简单,不要被吓到…… 思路:多项式除以另外一个多项式,如果能除,那么他的最高次一定被降低了,如果最高次不能被降低,那说明已经无法被除,就是题 ...
- Lintcode: Hash Function && Summary: Modular Multiplication, Addition, Power && Summary: 长整形long
In data structure Hash, hash function is used to convert a string(or any other type) into an integer ...
- poj 1060
http://poj.org/problem?id=1060 题意:多项式的运算的题目,不过这个运算有个特点,就是只要是同项的多项式,无论相加还是相减,都为0,给你三个多项式,分别为a,b,c. 要你 ...
- POJ 3673 Cow Multiplication
Cow Multiplication Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13312 Accepted: 93 ...
- Poj 3318 Matrix Multiplication( 矩阵压缩)
Matrix Multiplication Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 18928 Accepted: ...
- poj 2505 A multiplication game(博弈)
A multiplication game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5622 Accepted: ...
随机推荐
- 树莓派--bcm2835 library (2) 交叉编译BCM2835
在上文中,按照guide, 在树莓派目标板上install bcm2835. 因为bcm2835是用户空间应用,所以可以在宿主机上交叉编译,生成binary后在树莓派执行 按照guide: Insta ...
- 10.Spring Bean的生命周期
Spring IOC容器可以管理Bean的生命周期,允许在Bean声明周期的特定点执行定制的任务. Spring IOC容器对Bean的生命周期进行管理的过程. 1.通过构造器或工厂方法创建Bean实 ...
- python 项目部署virtualenv
安装virtualenv---------------------------------------- mac: pip3 install virtualenv ubuntu: apt instal ...
- PHP:压缩 Zip
文章来源:http://www.cnblogs.com/hello-tl/p/7661222.html <?php # 文件字符集 header("Content-type: text ...
- Spider-Python爬虫之XPath 教程
原文链接:https://www.runoob.com/xpath/xpath-syntax.html XPath 术语 XPath 节点 七种类型:在 XPath 中,有七种类型的节点:元素.属性. ...
- 90-Standard Deviation 标准离差指标.(2015.7.4)
Standard Deviation 标准离差指标 ~计算: StdDev = SQRT (SUM (CLOSE - SMA (CLOSE, N), N)^2)/N 注解: SQRT - 正方体根: ...
- 75-ADMI,Average Directional Movement Index,平均方向性运动指标.(2015.7.1)
ADMI,Average Directional Movement Index 平均方向性运动指标 Directional Movement Index,平均方向性运动指标.(2015.7.1)&qu ...
- i2c精简总结
基本的i2c的编程包括:读数据,写命令,写数据 有关i2c的时序需要的话查看这里http://blog.csdn.net/qqliyunpeng/article/details/41511347 1. ...
- spring+orm框架的兼容问题
Springframework和Hibernate版本对应关系 org.springframework 3.0.x对应org.hibernate4.0.x版本 org.springframework ...
- 九度oj 题目1061:成绩排序
题目1061:成绩排序 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:24473 解决:6960 题目描述: 有N个学生的数据,将学生数据按成绩高低排序,如果成绩相同则按姓名字符的字母序排 ...