萌新求助 如何在主函数里重定义运算符 悬赏关注
查看原帖
萌新求助 如何在主函数里重定义运算符 悬赏关注
167875
137QWQ楼主2022/10/27 21:49
#include<bits/stdc++.h>
#define ll long long
using namespace std;
struct node
{
    ll c[105][105];
}A,I;
const ll Mod=1e9+7;
ll n,k;
node operator*(const node &x,const node &y)
{
    node a; memset(a.c,0,sizeof(a.c));
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            for(int k=1;k<=n;k++)
                a.c[i][j]=(a.c[i][j]+x.c[i][k]*y.c[k][j]%Mod)%Mod;
    return a;
}
int main()
{
    cin>>n>>k;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            cin>>A.c[i][j];
    memset(I.c,0,sizeof(I.c));
    for(int i=1;i<=n;i++)
        I.c[i][i]=1;
    while(k>0)
    {
        if(k%2==1) I=I*A;
        A=A*A;
        k=k>>1;
    }
    
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
            cout<<I.c[i][j]<<" ";
        cout<<endl;
    }
}

如何在需要的时候将*重定义而不是一开始就重定义呢qwq

2022/10/27 21:49
加载中...