A Linear Algebra Problem(唯一性的判定)

A Linear Algebra Problem

Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others)
Submit Status

God Kufeng is the God of Math. However, Kufeng is not so skilled with linear algebra, especially when dealing with matrixes.

One day, Captain Chen has a problem with matrix, here is the problem:

Given a n×n matrix A, what is the solution of n×n matrix X for the equation AX+XA=2A?

Captain Chen is a nice Captain, he wants to solve the equation only when A is a diagonal matrix, which means Aij=0 holds for all ij .

“That’s easy!” says Kufeng, “the answer is simply X=I, when I is the Identity Matrix.”

“But… is it the only solution for the equation above?” Captain Chen asks.

Kufeng cannot answer this question, can you help him?

Input

The first line of input is a number n, giving the size of matrix A and X(1n1000)

Then comes a single line with n numbers, x1,x2,,xn, where xi is the value of Aii(10000xi10000)

Output

If the answer is unique, output UNIQUE, otherwise output NOT UNIQUE

Sample input and output

Sample InputSample Output
3
1 2 3
UNIQUE
2
1 -1
NOT UNIQUE

Hint

For the second sample input, A=(1001), there can be more than one possible solutions for X, for example, X=(1001) and X=(1101) both satisfy the equation, so the answer is not unique.

题目大意:

  给你一个n维的对角矩阵A,然后有一个n维的矩阵X,使得AX+XA=2A的等式成立的条件下,要让X唯一,那么A应该满足什么样的条件?

解题思路:

  刚读完题目后,以为是个找规律的题目,但是一想,还是错了,其实就是简单的矩阵推导了。

  首先,对于单位阵X,那么一定有AX+XA=2A成立。现在来考虑,一般的情况。

  令2A=B,那么,B[i,i] = A[i,i]*X[i,i]+X[i,i]*A[i,i] = 2*A[i,i]*X[i,i] = 2*A[i,i] ->如果要使X唯一,那么A[i,i]!=0.

          B[i,j] = A[i,i]*X[i,j]+X[i,j]*A[j,j] = X[i,j]*(A[i,i]+A[j,j])=0 要使得X唯一,那么(A[i,i]+A[j,j])!=0.

  这样一来,我们就发现了,在A的对角线上的元素不能有0和互为相反数的数了。

代码:

# include<cstdio>
# include<iostream>
# include<algorithm>

using namespace std;

# define MAX 1000+4

int a[MAX];

int main(void)
{
    int n;cin>>n;
    int flag = 0;
    for ( int i = 0;i < n;i++ )
    {
        cin>>a[i];
        if ( a[i]==0 )
        {
            flag = 1;
        }
    }
    if ( !flag )
        {
            sort(a,a+n);
            for ( int i = 0;i < n;i++ )
        {
            if ( a[i]>0||flag == 1 )
                break;
            for ( int j = n-1;j >= i;j-- )
            {
                if ( a[j]+a[i]==0 )
                {
                    flag = 1;
                    break;
                }
                else if ( a[j] < 0 )
                    break;
                else
                    continue;
            }

        }
        }
    if ( flag )
        cout<<"NOT UNIQUE"<<endl;
    else
        cout<<"UNIQUE"<<endl;



    return 0;
}

  

转载于:https://www.cnblogs.com/wikioibai/p/4374927.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值