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. jenkins 使用的python 不是指定的python 的解决方法

    构建的时候加上要使用python的解析器路径 终端 which python 可以找到 python编辑器里面 import os os.system("which python" ...

  2. MariaDB管理系统

    MariaDB管理系统 [root@c4kaichen@163 ~]# yum install mariadb[root@c4kaichen@163 ~]# yum install -y mariad ...

  3. 修改 Docker-MySQL 容器的 默认用户加密规则

    背景介绍 今天开始做集成测试,需要把程序和环境重新部署在新的服务器上.项目的环境都是基于Docker来的,所以数据库也是选择从Docker官网上面拉官方的MySQL镜像.(Tag = 8.0.12) ...

  4. Design a high performance cache for multi-threaded environment

    如何设计一个支持高并发的高性能缓存库 不 考虑并发情况下的缓存的设计大家应该都比较清楚,基本上就是用map/hashmap存储键值,然后用双向链表记录一个LRU来用于缓存的清理.这篇文章 应该是讲得很 ...

  5. vmware 共享文件夹(win10下的vmware安装了centos7)

    最近研究下了docker.我的笔记本是win10系统,就尝试使用了 win10的hyper-v虚拟化技术,总是感觉占用系统较多,于是换成了vmware,在虚拟机中安装 docker容器服务. 考虑到开 ...

  6. css3网站收集

    把群里大家推荐的网站做了下收集,等有时间了研究下 1.http://icomoon.io/app/  这个网站用来生成跟导出字体图标的,自带的图标种类很多很丰富,基本够用了,不过你也可以自己设计,然后 ...

  7. 《opencv学习》 之 特征检测与匹配

    这几天学习SURF特征检测,直接看的视频和书本有点吃不消,现在是基本看懂了,如果写博客记录没有必要,因为网上都差不多,笔记都在书上了,以下是个人认为比较浅显易懂的文章,当然海有很多好文章我没看到. 看 ...

  8. 数据库,mysql

    数据库(`database`): ### 关系型数据库及非关系型数据库1. 什么是关系型数据库? 关系型数据库是一种建立在关系模型上的数据库,借助于集合代数等数学概念和方法来处理数据库中的数据.现实世 ...

  9. 3.circle (圆)

    1.HTML代码: <div class="circleOne"></div> <br/> <div class="circle ...

  10. Windows系统下Eclipse上搭建Python开发环境

    参考网站:   https://blog.csdn.net/zhangphil/article/details/78962159 1.先安装JDK 和python,参考网站:https://www.c ...