因为freopen("in.txt","r",stdin);贡献了一个超时,以后就的最终代码就是把这行注释掉就行了。相比以前的
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
和最后的
fclose(stdin);
fclose(stdout);
四行冗余的代码来说,freopen("in.txt","r",stdin);一行足以(不但满足需求还顺眼),而且上交的时候只要注释一行即可。
#include<iostream>
#include<cstring>#include<cstdio>
#include<cmath>
using namespace std;
int a[1005];
int b[1005];
int c[1005];
int cun[2005];
int cun1[2005];
int main()
{
//freopen("in.txt","r",stdin);
int t;
scanf("%d",&t);
for(int i=0; i<t; i++)
{
int m,n,v;
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
memset(c,0,sizeof(c));
memset(cun,0,sizeof(cun));
memset(cun1,0,sizeof(cun1));
scanf("%d",&m);
for(int j=m-1; j>=0; j--)
scanf("%d",&a[j]);
scanf("%d",&n);
for(int j=n-1; j>=0; j--)
scanf("%d",&b[j]);
scanf("%d",&v);
for(int j=v-1; j>=0; j--)
scanf("%d",&c[j]);
;
for(int j=0; j<m; j++)
{
for(int k=0; k<n; k++)
{
cun[j+k]+=a[j]*b[k];
}
}
for(int j=0; j<m+n-2; j++)
cun[j]=cun[j]%2;
int cnt=m+n-2;
while(cnt-v+1>=0)
{
memset(cun1,0,sizeof(cun1));
for(int j=0; j<v; j++)
if(c[j])cun1[cnt-v+1+j]=1;
int flag=1;
for(int j=cnt; j>=0; j--)
{
cun[j]=abs(cun[j]-cun1[j]);
if(flag&&cun[j]==1)
{
cnt=j;
flag=0;
}
}
}
;
printf("%d",cnt+1);
for(int j=cnt;j>=0;j--)
printf(" %d",cun[j]);
putchar('\n');
}
return 0;
}