POJ 3318-Matrix Multiplication first solves the problem with randomization...

Source: Internet
Author: User

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;  }  

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.