24h購物| | PChome| 登入
2012-05-01 21:08:00| 人氣8,875| 回應0 | 上一篇 | 下一篇

[UVA] 11349 - Symmetric Matrix

推薦 0 收藏 0 轉貼0 訂閱站台

J - Symmetric Matrix

Time Limit: 1 sec
Memory Limit: 16MB

You`re given a square matrix M. Elements of this matrix are Mij: {0 < i < n, 0 < j < n}. In this problem you'll have to find out whether the given matrix is symmetric or not.

Definition: Symmetric matrix is such a matrix that all elements of it are non-negative and symmetric with relation to the center of this matrix. Any other matrix is considered to be non-symmetric. For example:

All you have to do is to find whether the matrix is symmetric or not. Elements of a matrix given in the input are -232 <= Mij <= 232 and 0 < n <= 100.

INPUT:

First line of input contains number of test cases T <= 300. Then T test cases follow each described in the following way. The first line of each test case contains n - the dimension of square matrix. Then n lines follow each of then containing row i. Row contains exactly n elements separated by a space character. j-th number in row i is the element Mij of matrix you have to process.

OUTPUT:

For each test case output one line "Test #t: S". Where t is the test number starting from 1. Line S is equal to "Symmetric" if matrix is symmetric and "Non-symmetric" in any other case.

SAMPLE INPUT:

2
N = 3
5 1 3
2 0 2
3 1 5
N = 3
5 1 3
2 0 2
0 1 5

SAMPLE OUTPUT:

Test #1: Symmetric.
Test #2: Non-symmetric.


這裡的對稱矩陣跟我們高中所學的不一樣, 是以中心為對稱的矩陣, 且不可有負數的元素
 
#include <stdio.h>

int main() {
    int t, n, Case = 0;
    long long map[101][101];
    char str[3];
    scanf("%d", &t);
    while(t--) {
        scanf("%s %s %d", str, str, &n);
        int flag = 0, i, j;
        for(i = 0; i < n; i++) {
            for(j = 0; j < n; j++) {
                scanf("%lld", &map[i][j]);
                if(map[i][j] < 0)   flag = 1;
            }
        }
        for(i = 0; i < n; i++) {
            for(j = 0; j < n-i; j++) {
                if(map[i][j] != map[n-1-i][n-1-j]) {
                    flag = 1;
                    goto end;
                }
            }
        }
        end:
        printf("Test #%d: ", ++Case);
        if(flag)
            puts("Non-symmetric.");
        else
            puts("Symmetric.");
    }
    return 0;
}

台長: Morris
人氣(8,875) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA][Java][Math] 10303 - How Many Trees?
此分類上一篇:[UVA] 11616 - Roman Numerals

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文