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 hheq121 at 2008-08-19 17:21:07 on Problem 2941 and last updated at 2008-08-19 17:30:35
我们只要改变其中的任意两个数,就可以得到另外的一种选法,
而在改变的时候必然是行和列相互对换的,
例如,我们保持其它的不变,我们原本选了(1,1)(2,2)(3,3)(4,4)
 我们选取其中的(1,1)(3,3),则我们应改为(1,3)(3,1)
则只要(1,3)(3,1)的和与(1,1)(3,3)的和相等即可!
这样实际上也就是说在任意能组成一个正方形的四个数的对角线上的和相等就可以了!
做一个循环就可以解决问题!
附代码:
#include<iostream>
using namespace std;
int p[1005][1005];
int main()
{
	int n,i,j;
	while(1)
	{
		scanf("%d",&n);
		if(n==0)
			break;
		for(i=0;i<n;i++)
			for(j=0;j<n;j++)
				scanf("%d",&p[i][j]);
		int ture=1;
		for(i=0;i<n-1;i++)
		{
			for(j=0;j<n-1;j++)
				if(p[i][j]+p[i+1][j+1]!=p[i][j+1]+p[i+1][j])
				{
					ture=0;
					break;
				}
			if(ture==0)
				break;
		}
		if(ture==1)
			printf("homogeneous\n");
		else
			printf("not homogeneous\n");
	}
	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