Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Memory: 184K Time: 0MS#include<stdlib.h> #include<stdio.h> #include<string.h> #define N 2010 void specialMult(int* x,int* y,int* ans) { int temp[N],i,j,t; memset(temp,0,sizeof(temp)); for (i=1;i<=y[0];i++) { t=0; for (j=1;j<=x[0];j++) temp[i+j-1]= temp[i+j-1]^(x[j]*y[i]); if (i+j-2>temp[0]) temp[0]=i+j-2; //-2是因为j在跳出上面的for循环之前还会加1 } memcpy(ans,temp,(temp[0]+1)*sizeof(temp[0])); } void Reversal(int* s) { int i,t; for (i=1;i<=(s[0]>>1);i++) { t=s[i]; s[i]=s[s[0]-i+1]; s[s[0]-i+1]=t; } } void specialDiv(int* x,int* y, int* left) // x/y = ans ... left { int temp_left[N]; memcpy(temp_left, x, sizeof(int)*N); int n; while (temp_left[0] >= y[0]){ n = temp_left[0] - y[0]; for(int i = 1; i <= y[0]; i ++) temp_left[i+n] = temp_left[i+n]^y[i]; while (temp_left[0]>=1&&!temp_left[temp_left[0]]) // note: >= 1 temp_left[0]--; } memcpy(left,temp_left,(temp_left[0]+1)*sizeof(temp_left[0])); } void Input(int* s){ int n; int digit; scanf("%d", &n); s[0] = 0; for (int i = 0; i < n; i ++){ scanf("%d", &digit); s[++s[0]] = digit; } } void Output(int* s){ if (s[0] == 0) { printf("0 0\n"); return; } printf("%d ", s[0]); for(int i = s[0]; i >= 1; i --) printf("%d ", s[i]); printf("\n"); } int main(){ int x[N/2], y[N/2], z[N/2]; int ans[N]; int k; scanf("%d", &k); for(int i = 0; i < k; i ++){ Input(x); Reversal(x); Input(y); Reversal(y); Input(z); Reversal(z); specialMult(x, y, ans); specialDiv(ans, z, ans); Output(ans); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator