http://acm.uestc.edu.cn/#/problem/show/793

 

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

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 A?

Captain Chen is a nice Captain, he wants to solve the equation only when A is a diagonal matrix, which means j .

“That’s easy!” says Kufeng, “the answer is simply 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 )

Then comes a single line with )

Output

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

Sample input and output

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

Hint

For the second sample input, ) both satisfy the equation, so the answer is not unique.

 

题意:矩阵A满足非主对角线外所有元素为0,有一矩阵X,满足AX+XA=2A。问这样的X是否是唯一的。

思路:首先,X为单位矩阵,是满足算式的。然后讨论下:设最后的矩阵2A为矩阵B。当i=j时,bii=aii*xii+xii*aii=2*aii*xii=2*aii。也就是说,如果想要xii是唯一的,即1,那么aii就非0。当i!=j时,bij=aii*xij+xij*ajj=xij*(aii+ajj)=0. 也就是说,想要xij唯一,即0,那么aii+ajj就非0. 故而,如果X唯一,那么矩阵A的主对角线上元素必须满足两个条件:不存在0且不存在相反数。

代码

 1 #include <fstream>
 2 #include <iostream>
 3 #include <algorithm>
 4 #include <cstdio>
 5 #include <cstring>
 6 #include <cmath>
 7 #include <cstdlib>
 8 #include <queue>
 9 
10 using namespace std;
11 
12 #define PI acos(-1.0)
13 #define EPS 1e-12
14 #define lll __int64
15 #define ll long long
16 #define INF 0x7fffffff
17 
18 int a[1002];
19 bool b;
20 
21 int main(){
22     //freopen("D:\\input.in","r",stdin);
23     //freopen("D:\\output.out","w",stdout);
24     int n;
25     scanf("%d",&n);
26     for(int i=0;i<n;i++){
27         scanf("%d",&a[i]);
28         if(a[i]==0) b=1;
29     }
30     if(!b){
31         sort(a,a+n);
32         for(int i=0;i<n;i++){
33             if(a[i]>0||b)  break;
34             for(int j=n-1;j>i;j--){
35                 if(a[i]+a[j]==0){
36                     b=1;
37                     break;
38                 }else if(a[i]+a[j]<0)
39                     break;
40             }
41         }
42     }
43     if(b)   puts("NOT UNIQUE");
44     else    puts("UNIQUE");
45     return 0;
46 }
View Code

相关文章:

  • 2021-10-31
  • 2021-05-29
  • 2021-04-27
  • 2021-12-18
  • 2021-08-04
  • 2021-08-04
  • 2021-03-31
  • 2021-12-12
猜你喜欢
  • 2022-01-17
  • 2021-07-10
  • 2021-08-01
  • 2021-09-25
  • 2021-09-28
  • 2021-10-21
  • 2021-06-06
相关资源
相似解决方案