Esempio n. 1
0
        public static int[,] Traspuesta(int[,] matriz, Región r) {
            if(r.tamaño > 0) {
                int[,] result = new int[r.tamaño, r.tamaño];

                if(r.tamaño > 1) {
                    int mitad = r.tamaño / 2;
                    // Partición
                    int[,] r1 = Traspuesta(matriz, new Región(r.f, r.c, mitad));
                    int[,] r2 = Traspuesta(matriz, new Región(r.f, r.c + mitad, mitad));
                    int[,] r3 = Traspuesta(matriz, new Región(r.f + mitad, r.c, mitad));
                    int[,] r4 = Traspuesta(matriz, new Región(r.f + mitad, r.c + mitad, mitad));
                    // Combinación
                    for(int i = 0; i < mitad; i++) {
                        for(int j = 0; j < mitad; j++) {
                            result[i, j] = r1[i, j];
                            result[i, j + mitad] = r3[i, j];
                            result[i + mitad, j] = r2[i, j];
                            result[i + mitad, j + mitad] = r4[i, j];
                        }
                    }
                } else {
                    result[0, 0] = matriz[r.f, r.c];
                }

                return result;
            } else {
                return null;
            }
        }
Esempio n. 2
0
        public static Región BusqIter(int[,] matriz, int tam)
        {
            Región result = new Región();
            Región temp   = new Región();

            for (int i = 0; i < tam; i++)
            {
                if (result.tamaño >= tam - i)
                {
                    break;
                }
                for (int j = 0; j < tam; j++)
                {
                    if (result.tamaño >= tam - j)
                    {
                        break;
                    }
                    temp = BusqIter(matriz, i, j, tam);
                    if (temp.tamaño > result.tamaño)
                    {
                        result = temp;
                    }
                }
            }

            return(result);
        }
Esempio n. 3
0
 public static LinkedList <Rect> Busqueda(int[,] matriz, Región r)
 {
     if (r.tamaño > 0)
     {
         LinkedList <Rect> result = new LinkedList <Rect>();
         if (r.tamaño > 1)
         {
             int mitad = r.tamaño / 2;
             // Partición
             LinkedList <Rect> r1 = Busqueda(matriz, new Región(r.f, r.c, mitad));
             LinkedList <Rect> r2 = Busqueda(matriz, new Región(r.f, r.c + mitad, mitad));
             LinkedList <Rect> r3 = Busqueda(matriz, new Región(r.f + mitad, r.c, mitad));
             LinkedList <Rect> r4 = Busqueda(matriz, new Región(r.f + mitad, r.c + mitad, mitad));
             // Combinación
             foreach (Rect item in r1.Concat(r2).Concat(r3).Concat(r4))
             {
                 result.AddLast(item);
             }
             Combinación(matriz, result);
         }
         else
         {
             result.AddLast(new Rect(r.f, r.c, 1, 1));
         }
         return(result);
     }
     else
     {
         return(null);
     }
 }
Esempio n. 4
0
        public static Región BusqIter(int[,] matriz, int f, int c, int tam)
        {
            Región result = new Región(f, c, 1);
            int    n      = (f > c ? f : c);

            for (int i = 1; (n + i) < tam; i++)
            {
                if (matriz[f, c] != matriz[f + i, c + i])
                {
                    return(result);
                }
                else
                {
                    for (int j = i - 1; j >= 0; j--)
                    {
                        if (matriz[f, c] != matriz[f + j, c + i])
                        {
                            return(result);
                        }
                        if (matriz[f, c] != matriz[f + i, c + j])
                        {
                            return(result);
                        }
                    }
                    result.tamaño++;
                }
            }
            return(result);
        }
Esempio n. 5
0
        public static Región Busqueda(int[,] matriz, int tam)
        {
            Región result = new Región(0, 0, 0);

            foreach (Rect r in Busqueda(matriz, new Región(0, 0, tam)))
            {
                //if(r.alto == r.ancho && r.alto > 3) {
                //    Console.WriteLine("f: {0}", r.f);
                //    Console.WriteLine("c: {0}", r.c);
                //    Console.WriteLine("t: {0}", r.alto);
                //    Console.WriteLine();
                //}
                if (r.alto == r.ancho && result.tamaño < r.alto)
                {
                    result.f      = r.f;
                    result.c      = r.c;
                    result.tamaño = r.alto;
                }
            }
            return(result);
        }
Esempio n. 6
0
        public static int[,] Traspuesta(int[,] matriz, Región r)
        {
            if (r.tamaño > 0)
            {
                int[,] result = new int[r.tamaño, r.tamaño];

                if (r.tamaño > 1)
                {
                    int mitad = r.tamaño / 2;
                    // Partición
                    int[,] r1 = Traspuesta(matriz, new Región(r.f, r.c, mitad));
                    int[,] r2 = Traspuesta(matriz, new Región(r.f, r.c + mitad, mitad));
                    int[,] r3 = Traspuesta(matriz, new Región(r.f + mitad, r.c, mitad));
                    int[,] r4 = Traspuesta(matriz, new Región(r.f + mitad, r.c + mitad, mitad));
                    // Combinación
                    for (int i = 0; i < mitad; i++)
                    {
                        for (int j = 0; j < mitad; j++)
                        {
                            result[i, j]                 = r1[i, j];
                            result[i, j + mitad]         = r3[i, j];
                            result[i + mitad, j]         = r2[i, j];
                            result[i + mitad, j + mitad] = r4[i, j];
                        }
                    }
                }
                else
                {
                    result[0, 0] = matriz[r.f, r.c];
                }

                return(result);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 7
0
        public static void Resolver()
        {
            const int tamaño = 8;

            int[,] matriz = new int[tamaño, tamaño]
            {
                #region Ejemplo 1

                /*
                 * { 1, 1, 1, 0, 0, 0, 0, 0 },
                 * { 1, 1, 1, 0, 0, 0, 0, 0 },
                 * { 1, 1, 1, 0, 0, 0, 0, 0 },
                 * { 0, 0, 0, 1, 1, 1, 1, 0 },
                 * { 0, 0, 0, 1, 1, 1, 1, 0 },
                 * { 0, 0, 0, 1, 1, 1, 1, 0 },
                 * { 1, 1, 0, 1, 1, 1, 1, 0 },
                 * { 1, 1, 0, 0, 0, 0, 0, 0 }
                 * //*/
                #endregion

                #region Ejemplo 2

                /*
                 * { 1, 1, 1, 0, 0, 0, 0, 0 },
                 * { 1, 1, 1, 0, 0, 0, 0, 0 },
                 * { 1, 1, 1, 1, 1, 1, 1, 0 },
                 * { 0, 0, 1, 1, 1, 1, 1, 0 },
                 * { 0, 0, 1, 1, 1, 1, 1, 0 },
                 * { 0, 0, 1, 1, 1, 1, 1, 0 },
                 * { 1, 1, 1, 1, 1, 1, 1, 0 },
                 * { 1, 1, 0, 0, 0, 0, 0, 0 }
                 * //*/
                #endregion

                #region Ejemplo 3

                /*
                 * { 0, 0, 0, 0, 0, 0, 0, 0 },
                 * { 0, 0, 0, 0, 0, 0, 0, 0 },
                 * { 0, 0, 0, 0, 0, 0, 0, 0 },
                 * { 0, 0, 0, 1, 1, 1, 1, 0 },
                 * { 0, 0, 0, 1, 1, 1, 1, 0 },
                 * { 0, 0, 0, 1, 1, 1, 1, 0 },
                 * { 0, 0, 0, 1, 1, 1, 1, 0 },
                 * { 0, 0, 0, 0, 0, 0, 0, 0 }
                 * //*/
                #endregion

                #region Ejemplo 4

                /*
                 * { 1, 1, 1, 0, 0, 0, 0, 0 },
                 * { 1, 1, 1, 1, 1, 1, 1, 0 },
                 * { 1, 1, 1, 1, 1, 1, 1, 0 },
                 * { 0, 0, 1, 1, 1, 1, 1, 0 },
                 * { 0, 0, 1, 1, 1, 1, 1, 0 },
                 * { 0, 0, 1, 1, 1, 1, 1, 0 },
                 * { 1, 1, 1, 1, 1, 1, 1, 0 },
                 * { 1, 1, 0, 0, 0, 0, 0, 0 }
                 * //*/
                #endregion

                #region Ejemplo 5
                //*
                { 1, 1, 1, 0, 0, 0, 0, 0 },
                { 1, 1, 1, 1, 1, 1, 1, 0 },
                { 1, 1, 1, 1, 1, 1, 1, 0 },
                { 0, 0, 1, 1, 1, 1, 1, 0 },
                { 0, 0, 1, 1, 1, 1, 1, 0 },
                { 0, 0, 1, 1, 1, 1, 1, 0 },
                { 1, 1, 0, 0, 0, 0, 0, 0 },
                { 1, 1, 0, 0, 0, 0, 0, 0 }
                //*/
                #endregion
            };

            Región result = BusqIter(matriz, tamaño);
            Console.WriteLine("f: {0}", result.f);
            Console.WriteLine("c: {0}", result.c);
            Console.WriteLine("t: {0}", result.tamaño);

            Console.WriteLine();
            result = Busqueda(matriz, tamaño);
            Console.WriteLine("f: {0}", result.f);
            Console.WriteLine("c: {0}", result.c);
            Console.WriteLine("t: {0}", result.tamaño);
        }
Esempio n. 8
0
 public static LinkedList<Rect> Busqueda(int[,] matriz, Región r) {
     if(r.tamaño > 0) {
         LinkedList<Rect> result = new LinkedList<Rect>();
         if(r.tamaño > 1) {
             int mitad = r.tamaño / 2;
             // Partición
             LinkedList<Rect> r1 = Busqueda(matriz, new Región(r.f, r.c, mitad));
             LinkedList<Rect> r2 = Busqueda(matriz, new Región(r.f, r.c + mitad, mitad));
             LinkedList<Rect> r3 = Busqueda(matriz, new Región(r.f + mitad, r.c, mitad));
             LinkedList<Rect> r4 = Busqueda(matriz, new Región(r.f + mitad, r.c + mitad, mitad));
             // Combinación
             foreach(Rect item in r1.Concat(r2).Concat(r3).Concat(r4)) {
                 result.AddLast(item);
             }
             Combinación(matriz, result);
         } else {
             result.AddLast(new Rect(r.f, r.c, 1, 1));
         }
         return result;
     } else {
         return null;
     }
 }
Esempio n. 9
0
        public static Región BusqIter(int[,] matriz, int tam) {
            Región result = new Región();
            Región temp = new Región();

            for(int i = 0; i < tam; i++) {
                if(result.tamaño >= tam - i) break;
                for(int j = 0; j < tam; j++) {
                    if(result.tamaño >= tam - j) break;
                    temp = BusqIter(matriz, i, j, tam);
                    if(temp.tamaño > result.tamaño) {
                        result = temp;
                    }
                }
            }

            return result;
        }
Esempio n. 10
0
        public static Región BusqIter(int[,] matriz, int f, int c, int tam) {
            Región result = new Región(f, c, 1);
            int n = (f > c ? f : c);

            for(int i = 1; (n + i) < tam; i++) {
                if(matriz[f, c] != matriz[f + i, c + i]) {
                    return result;
                } else {
                    for(int j = i - 1; j >= 0; j--) {
                        if(matriz[f, c] != matriz[f + j, c + i]) {
                            return result;
                        }
                        if(matriz[f, c] != matriz[f + i, c + j]) {
                            return result;
                        }
                    }
                    result.tamaño++;
                }
            }
            return result;
        }
Esempio n. 11
0
 public static Región Busqueda(int[,] matriz, int tam) {
     Región result = new Región(0, 0, 0);
     foreach(Rect r in Busqueda(matriz, new Región(0, 0, tam))) {
         //if(r.alto == r.ancho && r.alto > 3) {
         //    Console.WriteLine("f: {0}", r.f);
         //    Console.WriteLine("c: {0}", r.c);
         //    Console.WriteLine("t: {0}", r.alto);
         //    Console.WriteLine();
         //}
         if(r.alto == r.ancho && result.tamaño < r.alto) {
             result.f = r.f;
             result.c = r.c;
             result.tamaño = r.alto;
         }
     }
     return result;
 }