Randomization is still very powerful... the most impressive thing is that the previous handwritten fast sorting ~~ Generally, adding a randomization will make the time not consumed by the input data more stable ..
This question is a character question... it cannot be handed over many times. I finally handed over several times...
Program:
#include<iostream> #include<stack> #include<queue> #include<stdio.h> #include<algorithm> #include<string.h> #include<time.h> #include<cmath> #define ll long long #define oo 1000000007 #define MAXN 505 using namespace std; int n,M[3][MAXN][MAXN]; bool judge() { int t,i,j,x,y,p,d; for (t=1;t<=60000;t++) { y=rand()%n; x=rand()%n; d=0; for (p=0;p<n;p++) d+=M[0][y][p]*M[1][p][x]; if (d!=M[2][y][x]) return false; } return true; } int main() { int i,j,x; scanf("%d",&n); for (x=0;x<3;x++) for (i=0;i<n;i++) for (j=0;j<n;j++) scanf("%d",&M[x][i][j]); srand((unsigned)time(NULL)); if (judge()) printf("YES\n"); else printf("NO\n"); return 0; }