您的位置:首页 > 其它

POJ1060 Modular multiplication of polynomials

2016-07-29 13:57 351 查看
不想多说 全在代码里

#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

int g[1001],f[1001],s[2001],h[1001];
int lg,ls,lh,lf;
int i,j;

void mul() //乘
{

for( i=0; i<lg; i++)
for( j=0; j<lf; j++)
s[i+j] ^= g[i]*f[j];
ls=lg+lf-1;
return ;

}

void mod()
{
int t;
int res[2001];

while(ls>=lh)
{
memset(res,0,sizeof(res));
t=ls-lh;;
for( i=0; i<lh; i++)
{
if(h[i]==1)
res[i+t]=1;
}
for( i=ls-1; i>=t; i--)
s[i]^=res[i];
for( i=ls-1; i>=0; i--)
{
if(s[i])
{
ls=i+1;
break;
}
ls=0;
}
}
return ;

}
int main()
{
//freopen("in.txt","r",stdin);
int n;
scanf("%d",&n);
while(n--)
{
memset(s, 0, sizeof(s));
memset(f, 0, sizeof(f));
memset(g, 0, sizeof(g));
memset(h, 0, sizeof(h));

scanf("%d",&lg);
for( i=lg-1; i>=0; i--)
scanf("%d",&g[i]);
scanf("%d",&lf);
for( i=lf-1; i>=0; i--)
scanf("%d",&f[i]);
scanf("%d",&lh);
for( i=lh-1; i>=0; i--)
scanf("%d",&h[i]);
mul();
mod();
printf("%d",ls);
if(ls==0)
printf("0");
else
for( i=ls-1; i>=0; i--)
{
printf(" %d",s[i]);
}
printf("\n");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: