[一天至少一题直到ICPC开赛025]解题:Symmetric Matrix(1/8)

Symmetric Matrix

题目连结

找是不是对称矩阵(由中心点来镜射)不可以是负的

解题

a1 a2 a3b1 b2 b3c1 c2 c3

只要比较阵列的一半就好

如下图从a1开始(与c3比)

a1 x  xx  x  xx  x  c3

再来是b2 与 b3

x  x  xb1 x  b3x  x  x

最后是c1 与 a3

x  x  a3x  x  xc1 x  x

code

#include <iostream>#include <vector>#include <algorithm>#define ll long longusing namespace std;int main(int argc, char const *argv[]){    int t, count = 1;    cin >> t;    while (t--)    {        int n;        char s;        cin >> s >> s >> n;        int flag = 0;        vector<vector<ll>> matrix(n, vector<ll>(n, 0));        for (int i = 0; i < n; i++)        {            for (int j = 0; j < n; j++)            {                cin >> matrix[i][j];                if (matrix[i][j] < 0)                {                    flag = 1;                }            }        }        int mid = n / 2 - 1;        for (int i = 0; i < n; i++)        {            for (int j = 0; j <= mid; j++)            {                if (matrix[i][j] != matrix[n - i - 1][n - j - 1])                {                    flag = 1;                    break;                }            }        }        cout << "Test #" << count << ": ";        count++;        if (flag == 0)        {            cout << "Symmetric." << endl;        }        else        {            cout << "Non-symmetric." << endl;        }    }    return 0;}

关于作者: 网站小编

码农网专注IT技术教程资源分享平台,学习资源下载网站,58码农网包含计算机技术、网站程序源码下载、编程技术论坛、互联网资源下载等产品服务,提供原创、优质、完整内容的专业码农交流分享平台。

热门文章