Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
我真差劲,用概率算法还TLE, 哪位高手帮一下我?#include<iostream> #include<memory> #include<cstdlib> using namespace std ; int MatrexA[500][500] , MatrexB[500][500], MatrexC[500][500] ; void main() { int Nums ; int item , jtem ; int XA[500], XB[500], XAB[500], XC[500] ; srand(500) ; for( item = 0; item < 500; item++ ) XB[item] = rand() % 10 + 1; while( cin >> Nums ) { for( item = 0; item < Nums; item++ ) for( jtem = 0; jtem < Nums; jtem++ ) cin >> MatrexA[item][jtem] ; for( item = 0; item < Nums; item++ ) for( jtem = 0; jtem < Nums; jtem++ ) cin >> MatrexB[item][jtem] ; for( item = 0; item < Nums; item++ ) for( jtem = 0; jtem < Nums; jtem++ ) cin >> MatrexC[item][jtem] ; memset( XA, 0, sizeof(int) * Nums ) ; memset( XAB, 0, sizeof(int) * Nums ) ; memset( XC, 0, sizeof(int) * Nums ) ; for( item = 0; item < Nums; item++ ) for( jtem = 0; jtem < Nums; jtem++ ) XA[item] += MatrexB[item][jtem] * XB[jtem] ; for( item = 0; item < Nums ; item++ ) { for( jtem = 0; jtem < Nums; jtem++ ) { XC[item] += MatrexC[item][jtem] * XB[jtem] ; XAB[item] += MatrexA[item][jtem] * XA[jtem] ; } if( XAB[item] != XC[item] ) { cout << "NO\n" ; break ; } } if( item == Nums ) cout << "YES\n" ; } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator