Waterloo Cup--the seventh annual final: Anti-magic square

Source: Internet
Author: User
Anti-Magic Square


China's ancient books are very early records


2 9 4
7 5 3
6 1 8


This is a third-order magic square. Each row and the number on the diagonal are added equally.


Consider one of the opposite questions below.
You can not fill Hu Ci sudoku with 1~9 numbers.
So that the numbers on each diagonal of each row and column are not equal.




This should be done.
Like what:
9 1 2
8 4 3
7 5 6


Your task is to search all third-order anti-magic squares. And count out how many species there are.
Rotate or mirror the same species.


Like what:
9 1 2
8 4 3
7 5 6


7 8 9
5 4 1
6 3 2


2 1 9
3 4 8
6 5 7


And so on are counted in the same situation.


Please submit the third-order anti-magic square altogether how many kinds. This is an integer and do not fill in any excess content.

Direct violence Search bar, the most practical game

public class anti-magic square {static int arr[]={1,2,3,4,5,6,7,8,9};
	static int count=0;
		public static void Main (string[] args) {dfs (0);
	System.out.println (COUNT/8); public static void Dfs (int k) {if (k==arr.length) {if (Arr[0]+arr[1]+arr[2]!=arr[3]+arr[4]+arr[5]&&arr[0]+ar r[1]+arr[2]!=arr[6]+arr[7]+arr[8]&&arr[0]+arr[1]+arr[2]!=arr[3]+arr[0]+arr[6]&&arr[0]+arr[1]+ ARR[2]!=ARR[1]+ARR[4]+ARR[7]&&ARR[0]+ARR[1]+ARR[2]!=ARR[5]+ARR[2]+ARR[8]&&ARR[0]+ARR[1]+ARR[2] !=ARR[0]+ARR[4]+ARR[8]&&ARR[0]+ARR[1]+ARR[2]!=ARR[2]+ARR[4]+ARR[6]) if (Arr[3]+arr[4]+arr[5]!=arr[6]+arr [7]+arr[8]&&arr[3]+arr[4]+arr[5]!=arr[0]+arr[3]+arr[6]&&arr[3]+arr[4]+arr[5]!=arr[1]+arr[4]+ ARR[7]&&ARR[3]+ARR[4]+ARR[5]!=ARR[2]+ARR[8]+ARR[5]&&ARR[3]+ARR[4]+ARR[5]!=ARR[0]+ARR[4]+ARR[8] &&ARR[3]+ARR[4]+ARR[5]!=ARR[2]+ARR[4]+ARR[6]) if (arr[6]+arr[7]+arr[8]!=arr[0]+arr[3]+arr[6]&& Arr[6]+arr[7]+arr[8]!=arr[1]+arr[4]+arr[7]&&aMp;arr[6]+arr[7]+arr[8]!=arr[2]+arr[8]+arr[5]&&arr[6]+arr[7]+arr[8]!=arr[0]+arr[4]+arr[8]&&arr [6]+arr[7]+arr[8]!=arr[2]+arr[4]+arr[6]) if (arr[0]+arr[3]+arr[6]!=arr[1]+arr[4]+arr[7]&&arr[0]+arr[3]+ ARR[6]!=ARR[2]+ARR[8]+ARR[5]&&ARR[0]+ARR[3]+ARR[6]!=ARR[0]+ARR[4]+ARR[8]&&ARR[0]+ARR[3]+ARR[6] !=ARR[2]+ARR[4]+ARR[6]) if (Arr[1]+arr[4]+arr[7]!=arr[2]+arr[8]+arr[5]&&arr[1]+arr[4]+arr[7]!=arr[0]+arr [4]+arr[8]&&arr[1]+arr[4]+arr[7]!=arr[2]+arr[4]+arr[6]) if (arr[2]+arr[5]+arr[8]!=arr[0]+arr[4]+arr[8]& AMP;&ARR[2]+ARR[5]+ARR[8]!=ARR[2]+ARR[4]+ARR[6]) if (arr[0]+arr[4]+arr[8]!=arr[2]+arr[4]+arr[6]) cou
			nt++;
		Return
			for (int i=k;i<arr.length;i++) {int t=arr[k];
			Arr[k]=arr[i];
			arr[i]=t;
			DFS (K+1);
			T=ARR[K];
			Arr[k]=arr[i];
		arr[i]=t; }
	}
}



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.