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

不知道随机化是不是这么做,老WA啊!!!

Posted by IamI at 2005-08-06 15:42:00 on Problem 2531
#include<iostream.h>
#include<stdlib.h>

void main(){
	int i,j,n,n2,time,a[20],t[20][20];
	long sum,max;

	cin>>n;  max=-1; n2=(n+1)/2;
	for(i=0;i<n;i++)
		for(j=0;j<n;j++)
			cin>>t[i][j];

	time=200000;

	while(time--){
		sum=0;

		for(i=0;i<n;i++) a[i]=0;

		for(i=0;i<n2;i++) a[rand()%n]=1;

		for(i=0;i<n;i++)
			for(j=0;j<n;j++)
			if(  (a[i]) && (!a[j])  ) sum+=t[i][j];

		if(sum>max) max=sum;
	}

	cout<<max<<endl;
}

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