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

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 i≠j .

“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. (1≤n≤1000)

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

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, A=(100−1), 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且不存在相反数。

代码

 #include <fstream>
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <queue> using namespace std; #define PI acos(-1.0)
#define EPS 1e-12
#define lll __int64
#define ll long long
#define INF 0x7fffffff int a[];
bool b; int main(){
//freopen("D:\\input.in","r",stdin);
//freopen("D:\\output.out","w",stdout);
int n;
scanf("%d",&n);
for(int i=;i<n;i++){
scanf("%d",&a[i]);
if(a[i]==) b=;
}
if(!b){
sort(a,a+n);
for(int i=;i<n;i++){
if(a[i]>||b) break;
for(int j=n-;j>i;j--){
if(a[i]+a[j]==){
b=;
break;
}else if(a[i]+a[j]<)
break;
}
}
}
if(b) puts("NOT UNIQUE");
else puts("UNIQUE");
return ;
}

cdoj793-A Linear Algebra Problem的更多相关文章

  1. 「2020-2021 集训队作业」Yet Another Linear Algebra Problem(行列式,Binet-Cauchy 公式)

    题面 出题人:T L Y \tt TLY TLY 太阳神:Tiw_Air_OAO 「 2020 - 2021 集 训 队 作 业 」 Y e t A n o t h e r L i n e a r A ...

  2. Python Linear algebra

    Linear algebra 1.模块文档 NAME numpy.linalg DESCRIPTION Core Linear Algebra Tools ---------------------- ...

  3. 线性代数导论 | Linear Algebra 课程

    搞统计的线性代数和概率论必须精通,最好要能锻炼出直觉,再学机器学习才会事半功倍. 线性代数只推荐Prof. Gilbert Strang的MIT课程,有视频,有教材,有习题,有考试,一套学下来基本就入 ...

  4. Here’s just a fraction of what you can do with linear algebra

    Here’s just a fraction of what you can do with linear algebra The next time someone wonders what the ...

  5. Linear Algebra lecture1 note

    Professor: Gilbert Strang Text: Introduction to Linear Algebra http://web.mit.edu/18.06   Lecture 1 ...

  6. 算法库:基础线性代数子程序库(Basic Linear Algebra Subprograms,BLAS)介绍

    调试DeepFlow光流算法,由于作者给出的算法是基于Linux系统的,所以要在Windows上运行,不得不做大量的修改工作.移植到Windows平台,除了一些头文件找不到外,还有一些函数也找不到.这 ...

  7. 个案排秩 Rank (linear algebra) 秩 (线性代数)

    非叫“秩”不可,有秩才有解_王治祥_新浪博客http://blog.sina.com.cn/s/blog_8e7bc4f801012c23.html 我在一个大学当督导的时候,一次我听一位老师给学生讲 ...

  8. 读Linear Algebra -- Gilbert Strang

    转眼间我的学士学位修读生涯已经快要到期了,重读线性代数,一是为了重新理解Algebra的的重要概念以祭奠大一刷过的计算题,二是为了将来的学术工作先打下一点点(薄弱的)基础.数学毫无疑问是指导着的科研方 ...

  9. Codeforces Gym101502 B.Linear Algebra Test-STL(map)

    B. Linear Algebra Test   time limit per test 3.0 s memory limit per test 256 MB input standard input ...

随机推荐

  1. 通过textarea标签解决ClipboardJS在iphone复制失败问题

    前段时间做了微信自定义分享的功能,分享出的页面存在邀请码在ios手机上复制失败的问题,然而在PC端和安卓机上是没有问题的.百度了一下,基本给出的解决方案是:ios不单纯支持on,为点击的元素添加空点击 ...

  2. java日期比较例子等...

    数据库中employ表,入职日期,今天日期: 测试代码: package javademo; import java.sql.Connection; import java.sql.DriverMan ...

  3. selenium page object模式

    页面对象模式将测试代码和被测试页面的元素及操作进行分离,以降低页面元素的变化对测试代码的影响.每个被测试的页面都会被定义一个类,类中会定位元素和操作. 如果不使用page object模式,则相同的操 ...

  4. 设置redis 密码

    redis配置密码 1.通过配置文件进行配置 yum方式安装的redis配置文件通常在/etc/redis.conf中,打开配置文件找到 [plain] view plain copy require ...

  5. UMG设置组件自适应居中或靠边

    转自:http://aigo.iteye.com/blog/2297430 比如你的UI中有些组件需要居中显示,有些需要始终在右上角并且与上边框和右边框保持固定的距离等等,对于这种需要动态适应屏幕分辨 ...

  6. 可怕的SCN!(转载)

    一.什么是SCNSCN(System Change Number 简称 SCN)是当Oracle数据库更新后,由DBMS自动维护去累积递增的一个数字.在Oracle中,有四种SCN,分别为:系统检查点 ...

  7. Memcached缓存框架

    开发基于BS模式的程序,都有报表模块,那么如何开发报表模块. 1.定时发布报表数据到指定的临时表(可能是定时任务) 2.用户通过HTTP请求后台,访问临时表,查询报表数据 3.增加memcached缓 ...

  8. 学习MongoDB 八: MongoDB索引(索引限制条件)(二)

    一.简介 我们上一篇介绍了索引基本操作,通过db.collection.createIndex(keys, options)语法创建索引,我们继续介绍地理空间索引.索引的限制,使我们在MongoDB时 ...

  9. [Python] numpy.logspace

    numpy.logspace(start, stop, num=50, endpoint=True, base=10.0, dtype=None) starting value  :=  base** ...

  10. video元素和audio元素

    内容: 1.video元素 2.audio元素 注:这两个元素均是HTML5新增的元素 1.video元素 (1)用途 <video> 标签定义视频,比如电影片段或其他视频流 (2)标签属 ...