Logo

Greetings from The On-Line Encyclopedia of Integer Sequences!

Hints

Search: id:A133143
Displaying 1-1 of 1 results found. page 1
     Format: long | short | internal | text      Sort: relevance | references | number      Highlight: on | off
A133143 Maximal mumber of mutually nonattacking Super Queens on an n X n board. (a Super Queen is a queen with both queen and knight powers). +0
1
1, 1, 1, 2, 4, 4, 5, 6, 8, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 (list; graph; listen)
OFFSET

1,4

LINKS

Author?, More Information

EXAMPLE

a(4) = 2:

|X|0|0|0|

|0|0|0|X|

|0|0|0|0|

|0|0|0|0|

where X denotes the place of a Super Queen.

PROGRAM

(JAVA) import java.util.*;

import javax.swing.*;

public class SuperQueen{

public static int N;

public static Set knightMove;

public static int noOfMoves = 0;

public static int max = 0;

public static void main(String args[]){

String in = JOptionPane.showInputDialog(null, "Enter the size of board");

N = Integer.parseInt(in);

int ans[] = new int[N];

Set col = new HashSet();

Set diag45 = new HashSet();

Set diag135 = new HashSet();

knightMove = new HashSet();

ans = queens(1, col, diag45, diag135);

System.out.println("Maximum No. of Super Queens for the " + N + "x" + N + "board:" + max); }

public static int[] queens(int k, Set col, Set diag45, Set diag135){

int sol[] = new int[N+1];

OrdSet oSet;

int j;

if(k < N+1){

if(noOfMoves == N){

System.out.println("Maximum No. of Moves for the " + N + "x" + N + "board:" + max);

System.exit(0); }

else{

for(j = 1; j < N+1; j++ ){

if(!col.contains(j) && !diag45.contains(j-k) && !diag135.contains(j+k) && chkPos(k, j)){

sol[k] = j;

col.add(j);

diag45.add(j-k);

diag135.add(j+k);

//Adding Knight Moves

oSet = new OrdSet(k, j);

knightMove.add(oSet);

noOfMoves++;

if(max < noOfMoves)

max = noOfMoves;

queens(k+1, col, diag45, diag135);

diag45.remove(j-k);

diag135.remove(j+k);

col.remove(j);

knightMove.remove(oSet);

noOfMoves--; } }

queens(k+1, col, diag45, diag135); } }

return sol; }

public static boolean chkPos(int x, int y){

Iterator it = knightMove.iterator();

boolean retValue = true;

if(knightMove.size() == 0)

return true;

while(it.hasNext()){

OrdSet oSet = (OrdSet)it.next();

if(Math.abs(oSet.getX()-x) < 3.0 && Math.abs(oSet.getY()-y) < 3.0){

retValue = false; } }

return retValue; }

public static class OrdSet{

private int X;

private int Y;

OrdSet(){

X = 0;

Y = 0; }

OrdSet(int x, int y){

X = x;

Y = y; }

public int getX(){

return X; }

public int getY(){

return Y; } } }

CROSSREFS

Sequence in context: A100921 A140201 A057861 this_sequence A085898 A058568 A058679

Adjacent sequences: A133140 A133141 A133142 this_sequence A133144 A133145 A133146

KEYWORD

hard,nonn

AUTHOR

Rachit Agrawal (rachit_agrawal(AT)daiict.ac.in), Dec 16 2007

page 1

Search completed in 0.002 seconds

Lookup | Welcome | Find friends | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Transforms | Puzzles | Hot | Classics
More pages | Superseeker | Maintained by N. J. A. Sloane (njas@research.att.com)

Last modified December 4 15:51 EST 2008. Contains 151308 sequences.


AT&T Labs Research