cdoj793-A Linear Algebra Problem
http://acm.uestc.edu.cn/#/problem/show/793
A Linear Algebra Problem
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 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 |
UNIQUE |
2 |
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的更多相关文章
- 「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 ...
- Python Linear algebra
Linear algebra 1.模块文档 NAME numpy.linalg DESCRIPTION Core Linear Algebra Tools ---------------------- ...
- 线性代数导论 | Linear Algebra 课程
搞统计的线性代数和概率论必须精通,最好要能锻炼出直觉,再学机器学习才会事半功倍. 线性代数只推荐Prof. Gilbert Strang的MIT课程,有视频,有教材,有习题,有考试,一套学下来基本就入 ...
- 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 ...
- Linear Algebra lecture1 note
Professor: Gilbert Strang Text: Introduction to Linear Algebra http://web.mit.edu/18.06 Lecture 1 ...
- 算法库:基础线性代数子程序库(Basic Linear Algebra Subprograms,BLAS)介绍
调试DeepFlow光流算法,由于作者给出的算法是基于Linux系统的,所以要在Windows上运行,不得不做大量的修改工作.移植到Windows平台,除了一些头文件找不到外,还有一些函数也找不到.这 ...
- 个案排秩 Rank (linear algebra) 秩 (线性代数)
非叫“秩”不可,有秩才有解_王治祥_新浪博客http://blog.sina.com.cn/s/blog_8e7bc4f801012c23.html 我在一个大学当督导的时候,一次我听一位老师给学生讲 ...
- 读Linear Algebra -- Gilbert Strang
转眼间我的学士学位修读生涯已经快要到期了,重读线性代数,一是为了重新理解Algebra的的重要概念以祭奠大一刷过的计算题,二是为了将来的学术工作先打下一点点(薄弱的)基础.数学毫无疑问是指导着的科研方 ...
- 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 ...
随机推荐
- DNS 解释 --- 解析域名给电脑,电脑只看得懂1.1.1.1.1 这些ip地址 所以要翻译给他
把域名翻译成IP地址的软件称为域名系统,即DNS 当网络上的一台客户机需要访问某服务器上的资源时,客户机的用户只需要在浏览器中的地址文本框中输入该服务器的网址.就可以与该服务器进行连接,计算机的硬件只 ...
- POJ 1182 食物链(并查集的使用)
食物链 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 81915 Accepted: 24462 Description ...
- [转]IIS 允许/禁止 目录浏览
<?xml version="1.0" encoding="utf-8"?> <configuration> <system.we ...
- (转!)Netdata---Linux系统性能实时监控平台部署
我一直以为人是慢慢变老的,其实不是,人其实是一瞬间变老的. -------村上春树<舞!舞!舞!> 转自https://www.cnblogs.com/kevingrace/p/73001 ...
- 运行inetmgr提示“找不到文件”无法打开IIS管理器的解决办法
运行inetmgr提示“找不到文件”无法打开IIS管理器的解决办法 不知道什么时候开始运行inetmgr就提示找不到文件了,本以为是IIS坏了,这两天发现IIS服务还是可以运行的,只是运行inetmg ...
- 根据inode编号来删除文件或目录
在Linux系统上,有时候会出现文件名为特殊字符的文件或目录,当我们使用rm来删除这样的文件或目录时,就会出错导致删不掉.但是我们可以依据inode号来删除这样的文件,方法如下: (1)执行ls -i ...
- AVL树Python实现(使用递推实现添加与删除)
# coding=utf-8 # AVL树的Python实现(树的节点中包含了指向父节点的指针) def get_height(node): return node.height if node el ...
- python you-get 下载视频
python使用you-get模块下载视频 pip install you-get # 安装先 怎么用 进入命令行: you-get url 暂停下载:ctrl + c ,继续下载重复 y ...
- rsyslog编译依赖问题解决
bit-32-centos6.4测试loganalyzer+mysql+rsyslog web界面中央日志分析系统.1,报json-c错误wget http://cloud.github.com/ ...
- XE6 HTML设计器
XE6 自带的HTML编辑器很好用 File>New>Other>Web Documents>HTML Page 自动有code和Design,在Design标签可以拖放控件 ...