Question

In: Computer Science

Given a 2n × 2 n checkerboard with one square missing, construct a tiling of this...

Given a 2n × 2 n checkerboard with one square missing, construct a tiling of this checkerboard using right triominoes. Write a C or C++ program to solve this problem. The input is an integer n ≥ 3 and the position of the missing square. The output is a tiling of the 2n × 2 n checkerboard with one square missing (the position of the missing square is part of the input).

Solutions

Expert Solution

example
Input : size = 4 and mark coordinates = (0, 0)
Output :
-1      3       2       2
3       3       1       2
4       1       1       5
4       4       5       5

#include <bits/stdc++.h>

using namespace std;

int size_of_grid, b, a, cnt = 0;

int arr[128][128];

// Placing tile at the given coordinates

void place(int x1, int y1, int x2, int y2, int x3, int y3)

{

    cnt++;

    arr[x1][y1] = cnt;

    arr[x2][y2] = cnt;

    arr[x3][y3] = cnt;

}

// Function based on divide and conquer

int tile(int n, int x, int y)

{

    int r, c;

    if (n == 2) {

        cnt++;

        for (int i = 0; i < n; i++) {

            for (int j = 0; j < n; j++) {

                if (arr[x + i][y + j] == 0) {

                    arr[x + i][y + j] = cnt;

                }

            }

        }

        return 0;

    }

    for (int i = x; i < n; i++) // finding hole location

    {

        for (int j = y; j < n; j++) {

            if (arr[i][j] != 0)

                r = i, c = j;

        }

    }

    // If missing tile is in first quadrant

    if (r < x + n / 2 && c < y + n / 2)

        place(x + n / 2, y + (n / 2) - 1, x + n / 2,

              y + n / 2, x + n / 2 - 1, y + n / 2);

    // If missing Tile is in 2st quadrant

    else if (r >= x + n / 2 && c < y + n / 2)

        place(x + n / 2, y + (n / 2) - 1, x + n / 2,

              y + n / 2, x + n / 2 - 1, y + n / 2 - 1);

    // If missing Tile is in 3st quadrant

    else if (r < x + n / 2 && c >= y + n / 2)

        place(x + (n / 2) - 1, y + (n / 2), x + (n / 2),

              y + n / 2, x + (n / 2) - 1, y + (n / 2) - 1);

    // If missing Tile is in 4st quadrant

    else if (r >= x + n / 2 && c >= y + n / 2)

        place(x + (n / 2) - 1, y + (n / 2), x + (n / 2),

              y + (n / 2) - 1, x + (n / 2) - 1, y + (n / 2) - 1);

    // diving it again in 4 quadrants

    tile(n / 2, x, y + n / 2);

    tile(n / 2, x, y);

    tile(n / 2, x + n / 2, y);

    tile(n / 2, x + n / 2, y + n / 2);

    return 0;

}

// Driver program to test above function

int main()

{

    // size of box

    size_of_grid = 4;

    memset(arr, 0, sizeof(arr));

    // Coordinates which will be marked

    a = 0, b = 0;

    // Here tile can not be placed

    arr[a][b] = -1;

    tile(size_of_grid, 0, 0);

    // The grid is

    for (int i = 0; i < size_of_grid; i++) {

        for (int j = 0; j < size_of_grid; j++)

            cout << arr[i][j] << " \t";

        cout << "\n";

    }

}


Related Solutions

Prove the following by induction: 2 + 4 + 6 + …+ 2n = n(n+1) for...
Prove the following by induction: 2 + 4 + 6 + …+ 2n = n(n+1) for all integers n Show all work
a) Let T(n) be a running time function defined as T(n) = 3n^2 + 2n +...
a) Let T(n) be a running time function defined as T(n) = 3n^2 + 2n + 5, is this ϴ(n^2 )? Explain prove your answer using the definitions of big-o and omega notations. b) Solve the following recurrence relations using Master theorem. a. ?(?) = 3? ( ?/3 ) + ? b. ?(?) = 5?( ?/2 ) + 2?^2 please help them with both
Can you give me a turing machine for the language c* n b*2n a* n+2 for...
Can you give me a turing machine for the language c* n b*2n a* n+2 for n>=0 . Please give the entire diagram with states, transition function, alphabet. Can use either one-tape or two-tape (both infinite). Describe the logic used to build the machine. Run the TM that accepts for any string of length > 1. Also run for string cbba.
Show that the number of labelled simple graphs with n vertices is 2n(n-1)/2. (By induction way!)
Show that the number of labelled simple graphs with n vertices is 2n(n-1)/2. (By induction way!)
1a. Proof by induction: For every positive integer n, 1•3•5...(2n-1)=(2n)!/(2n•n!). Please explain what the exclamation mark...
1a. Proof by induction: For every positive integer n, 1•3•5...(2n-1)=(2n)!/(2n•n!). Please explain what the exclamation mark means. Thank you for your help! 1b. Proof by induction: For each integer n>=8, there are nonnegative integers a and b such that n=3a+5b
1) Find the radius of convergence and interval of convergence of the given series Σ x^2n/n!...
1) Find the radius of convergence and interval of convergence of the given series Σ x^2n/n! 2) Find the power series representation of f(x)=(x-1)/(x+2) first then find its interval of convergence.
(1)Prove 6^(2n)-4^(2n) must be a mutiple of 20 (2)Prove 6^(2n)+4^(2n)-2 must be a multiple of 50
(1)Prove 6^(2n)-4^(2n) must be a mutiple of 20 (2)Prove 6^(2n)+4^(2n)-2 must be a multiple of 50
Let An={2-n,2-2n,2-3n,…} where n∈N . Find A3∩A5 , A15∩A21 , A4∩A12 , Ak∩Akl , where k,l∈N...
Let An={2-n,2-2n,2-3n,…} where n∈N . Find A3∩A5 , A15∩A21 , A4∩A12 , Ak∩Akl , where k,l∈N . Prove also that A1∩A2∩A3∩A4∩…=∅ .
Diagram meiosis and mitosis in a 2N cell where N equals 2. In order to distinguish...
Diagram meiosis and mitosis in a 2N cell where N equals 2. In order to distinguish between the two chromosomes, make one long and one short. Also show the nuclear membrane, the spindle fibers, and the centriole. What are the main differences between meiosis and mitosis? Suppose the "a" locus is on one of these chromosomes and the parent cell has the genotype Aa. Label the alleles on the chromosomes and show how they behave in meiosis and mitosis if...
Find the sum (n=5, to infinity) of the series (n2 -n)/2n
Find the sum (n=5, to infinity) of the series (n2 -n)/2n
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT