[Unknow]神奇的矩阵
壹、题目描述 ¶
贰、题解 ¶
考虑两个矩阵直接相乘复杂度达到了 ,但是这道题显然是 的范围,我们不妨随机一个向量 ,然后检测 与 的结果,这样就变成了 的了。
叁、参考代码 ¶
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
#include<ctime>
using namespace std;
// #define NDEBUG
#include<cassert>
namespace Elaina{
#define rep(i, l, r) for(int i=(l), i##_end_=(r); i<=i##_end_; ++i)
#define drep(i, l, r) for(int i=(l), i##_end_=(r); i>=i##_end_; --i)
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)
#define Endl putchar('\n')
#define mmset(a, b) memset(a, b, sizeof a)
// #define int long long
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<class T>inline T fab(T x){ return x<0? -x: x; }
template<class T>inline void getmin(T& x, const T rhs){ x=min(x, rhs); }
template<class T>inline void getmax(T& x, const T rhs){ x=max(x, rhs); }
template<class T>inline T readin(T x){
x=0; int f=0; char c;
while((c=getchar())<'0' || '9'<c) if(c=='-') f=1;
for(x=(c^48); '0'<=(c=getchar()) && c<='9'; x=(x<<1)+(x<<3)+(c^48));
return f? -x: x;
}
template<class T>inline void writc(T x, char s='\n'){
static int fwri_sta[1005], fwri_ed=0;
if(x<0) putchar('-'), x=-x;
do fwri_sta[++fwri_ed]=x%10, x/=10; while(x);
while(putchar(fwri_sta[fwri_ed--]^48), fwri_ed);
putchar(s);
}
}
using namespace Elaina;
#define int long long
const int maxn=1000;
const int maxa=1000;
struct matrix{
int n, m;
int a[maxn+5][maxn+5];
matrix(){}
matrix(int N, int M): n(N), m(M){
rep(i, 1, n) rep(j, 1, m) a[i][j]=0;
}
inline void epsilon(int N){
n=m=N;
rep(i, 1, n) rep(j, 1, n) a[i][j]=(i==j);
}
inline matrix operator *(const matrix rhs) const{
assert(m==rhs.n);
matrix ret(n, rhs.m);
rep(i, 1, n) rep(j, 1, m) if(a[i][j])
rep(k, 1, rhs.m)
ret.a[i][k]+=a[i][j]*rhs.a[j][k];
return ret;
}
inline bool operator ==(const matrix rhs) const{
if(n!=rhs.n || m!=rhs.m) return false;
rep(i, 1, n) rep(j, 1, m)
if(a[i][j]!=rhs.a[i][j])
return false;
return true;
}
inline bool operator !=(const matrix rhs) const{
return !((*this)==rhs);
}
};
matrix a, b, c, vec;
int n;
inline int getrnd(){
return (rand()<<15|rand())%maxa;
}
inline void randVec(){
vec=matrix(1, n);
rep(i, 1, n) vec.a[1][i]=getrnd();
}
inline void input(){
a=b=c=matrix(n, n);
rep(i, 1, n) rep(j, 1, n)
a.a[i][j]=readin(1);
rep(i, 1, n) rep(j, 1, n)
b.a[i][j]=readin(1);
rep(i, 1, n) rep(j, 1, n)
c.a[i][j]=readin(1);
}
signed main(){
srand((unsigned)time(NULL));
while(~scanf("%d", &n)){
input();
bool flg=1;
rep(_, 1, 5){
randVec();
if(vec*a*b!=vec*c){
flg=false; break;
}
}
if(flg) printf("Yes\n");
else printf("No\n");
}
return 0;
}
肆、关键之处 ¶
一种奇怪的矩阵比较技巧。
分类:
数论/数学
, 数论/数学-线性代数
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
2020-07-22 [CF639D]Bear and Contribution