Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

O(n^3) AC

Posted by ragnarok01 at 2013-10-05 14:39:40 on Problem 3318 and last updated at 2013-10-05 14:42:21
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator