博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
cdoj793-A Linear Algebra Problem
阅读量:4672 次
发布时间:2019-06-09

本文共 2359 字,大约阅读时间需要 7 分钟。

 

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 Input Sample Output
31 2 3
UNIQUE
21 -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.

 

题意:矩阵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 
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 10 using namespace std;11 12 #define PI acos(-1.0)13 #define EPS 1e-1214 #define lll __int6415 #define ll long long16 #define INF 0x7fffffff17 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
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

 

转载于:https://www.cnblogs.com/jiu0821/p/4356589.html

你可能感兴趣的文章
回文日期(NOIP2016 普及组第二题)
查看>>
[jQuery]回到顶部
查看>>
Win7下修改Hosts文件
查看>>
Linq to sql并发与事务
查看>>
2017-06-27
查看>>
Convert DataTable to Html Table
查看>>
JavaEE复习三
查看>>
全局ajax事件
查看>>
javascript二维数组
查看>>
JavaScript 字符串属性和方法
查看>>
opencv新手注意
查看>>
Source InSight context 窗口丢失的解决办法
查看>>
cut point and bridge总结
查看>>
(5)Oracle基础--约束
查看>>
【Nginx】磁盘文件写入飞地发
查看>>
默认情况下安装的应用程序C盘后提示权限不足,当你开始介意。。。
查看>>
su root 后还是不能使用useradd ,useradd 等命令
查看>>
URL.createObjectURL图片预览
查看>>
js 中exec、test、match、search、replace、split用法
查看>>
Android开发笔记(一)手势识别
查看>>