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

暴力枚举居然也能过 无语 贴一下代码

Posted by zihuacs at 2010-06-15 12:19:25 on Problem 2078
#include <iostream>
#include <algorithm>
using namespace std;
int n;
int a[8][8];
int ans;
void  rota(int i)
{
	int temp;
	temp=a[i][n-1];
	int j;
	for(j=n-2;j>=0;j--)
		a[i][j+1]=a[i][j];
	a[i][0]=temp;
}
void solve(int i)
{
	if (i>n-1)
	{
		int sum;
		int max;
		int j;
		max=0x80000000;
		for (j=0;j<n;j++)
		{
			sum=0;
			for (i=0;i<n;i++)
			{
				sum+=a[i][j];
			}
			if (sum>max)
			{
				max=sum;
			}
		}
		if(ans>max)
			ans=max;
	}
	else
	{
		int k;
		for(k=0;k<n;k++)
		{
			rota(i);
			solve(i+1);
			
		}
	}
}
int main(void)
{
	int i,j;
	while(cin>>n && n!=-1)
	{
		for (i=0;i<n;i++)
		{
			for (j=0;j<n;j++)
			{
				cin>>a[i][j];
			}
		}
		ans=0x7fffffff;
		solve(0);
		cout<<ans<<endl;

	}
	return 0;
}




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