Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

我真差劲,用概率算法还TLE, 哪位高手帮一下我?

Posted by 200593141 at 2007-08-06 09:41:11 on Problem 3318
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator