matmul1.sy 1.49 KB
Newer Older
龚平's avatar
init  
龚平 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
int a[1000][1000];
int b[1000][1000];
int c[1000][1000];
const int MAX = 2147483647;

int main(){
    int n;
    int i;
    int j;
    int k;
    int sum = 0;

    i = 0;
    while(i<1000)
    {
        n = getarray(a[i]);
        if(n!=1000){
            return n;
        }
        i = i + 1;
    }

    starttime();

    i = 0;
    while(i<1000){
        j = 0;
        while(j<1000){
            b[i][j] = a[j][i];
            j = j+1;
        }
        i = i+1;
    }

    i = 0;
    while(i<1000){
        j = 0;
        while(j<1000){
            k = 0;
            int temp = 0;
            while(k<1000){
                temp = temp + a[i][k]*b[k][j];
                k = k+1;
            }
            c[i][j] = temp;
            j = j+1;
        }
        i = i+1;
    }

    i = 0;
    while(i<1000){
        j = 0;
        int temp = MAX;
        while(j<1000){
            if(c[i][j]<temp)
            {
                temp = c[i][j];
            }
            j = j+1;
        }
        j = 0;
        while(j<1000){
            c[i][j] = temp;
            j = j+1;
        }
        i = i+1;
    }

    i = 0;
    while(i<1000){
        j = 0;
        int temp = MAX;
        while(j<1000){
            c[i][j] = -c[j][i];
            j = j+1;
        }
        i = i+1;
    }

    i = 0;
    while(i<1000){
        j = 0;
        int temp = MAX;
        while(j<1000){
            sum = sum + c[i][j];
            j = j+1;
        }
        i = i+1;
    }

    stoptime();

    putint(sum);
    return 0;
}