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 |
O(n^3) AC#include<cstdio> int n,a[500][500],b[500][500],c[500][500]; inline int getint() { int d=0; char c,t=0; while((c=getchar())==' '||c=='\n'); if(c=='-') t=1; else d=c-'0'; while((c=getchar())>='0'&&c<='9') d=d*10+c-'0'; if(t) return -d; else return d; } void init() { n=getint(); int i,j; for(i=0;i<n;i++) for(j=0;j<n;j++) a[i][j]=getint(); for(i=0;i<n;i++) for(j=0;j<n;j++) b[i][j]=getint(); for(i=0;i<n;i++) for(j=0;j<n;j++) c[i][j]=getint(); } void solve() { int i,j,k,l; for(i=0;i<n;i++) { for(j=0;j<n;j++) { for(k=l=0;k<n;k++) l+=a[i][k]*b[k][j]; if(l!=c[i][j]) { puts("NO"); return; } } } puts("YES"); } int main() { init(); solve(); return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator