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 |
一次ac,0MS,200题发代码留念#include <iostream> using namespace std; void sub(int *a,int *b,int *res,int lena,int lenb) { for(int i=0;i<max(lena,lenb);i++) res[i]=a[i]^b[i]; } void multiply(int *a,int *b,int *res,int lena,int lenb) { for(int i=0;i<lena;i++) { for(int j=0;j<lenb;j++) { res[i+j]^=(a[i]*b[j]); } } } int main() { int a[2100],b[2100],temp[2100],res[2100],c[2100]; int testcase; cin>>testcase; int lena,lenb,lenres,lenc; while(testcase--) { memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); memset(res,0,sizeof(res)); memset(temp,0,sizeof(temp)); scanf("%d",&lena); for(int i=lena-1;i>=0;i--) scanf("%d",a+i); scanf("%d",&lenb); for(int i=lenb-1;i>=0;i--) scanf("%d",i+b); multiply(a,b,res,lena,lenb); lenres=lena+lenb-1; scanf("%d",&lenc); for(int i=lenc-1;i>=0;i--) scanf("%d",c+i); while(lenc<=lenres) { int diff=lenres-lenc; for(int i=0;i<diff;i++) temp[i]=0; for(int i=0;i<lenc;i++) temp[i+diff]=c[i]; sub(res,temp,res,lenres,lenres); int i; for(i=2099;i>=0;i--) { if(res[i]!=0) break; } lenres=i+1; } cout << lenres; for(int i=lenres-1;i>=0;i--) printf(" %d",res[i]); cout << endl; } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator