Exemple #1
0
        public static void Main()
        {
            var rooms = new List <IList <int> >()
            {
                new List <int> {
                    1, 3
                },
                new List <int> {
                    3, 0, 1
                },
                new List <int> {
                    2
                },
                new List <int> {
                    0
                },
            };

            var canVisit = CanVisitAllRooms(rooms);

            //FloodFill
            flood       = new int[3, 3];
            flood[0, 0] = 0;
            flood[0, 1] = 0;
            flood[0, 2] = 1;
            flood[1, 0] = 1;
            flood[1, 1] = 1;
            flood[1, 2] = 1;
            flood[2, 0] = 9;
            flood[2, 1] = 4;
            flood[2, 2] = 2;
            UpdateMatrix(flood);
            flood = FloodFill(flood, 1, 1, 1);

            var q = new BFSQueue
            {
                box = new int[4, 4]
            };

            q.box[0, 0] = INFINITY;
            q.box[0, 1] = -1;
            q.box[0, 2] = 0;
            q.box[0, 3] = INFINITY;
            q.box[1, 0] = INFINITY;
            q.box[1, 1] = INFINITY;
            q.box[1, 2] = INFINITY;
            q.box[1, 3] = -1;
            q.box[2, 0] = INFINITY;
            q.box[2, 1] = -1;
            q.box[2, 2] = INFINITY;
            q.box[2, 3] = -1;
            q.box[3, 0] = 0;
            q.box[3, 1] = -1;
            q.box[3, 2] = INFINITY;
            q.box[3, 3] = INFINITY;

            q.WallsAndGates(q.box);

            q.box1       = new char[5, 5];
            q.box1[0, 0] = '1';
            q.box1[0, 1] = '1';
            q.box1[0, 2] = '0';
            q.box1[0, 3] = '0';
            q.box1[0, 4] = '0';
            q.box1[1, 0] = '1';
            q.box1[1, 1] = '1';
            q.box1[1, 2] = '0';
            q.box1[1, 3] = '0';
            q.box1[1, 4] = '0';
            q.box1[2, 0] = '0';
            q.box1[2, 1] = '0';
            q.box1[2, 2] = '1';
            q.box1[2, 3] = '0';
            q.box1[2, 4] = '0';
            q.box1[3, 0] = '0';
            q.box1[3, 1] = '0';
            q.box1[3, 2] = '0';
            q.box1[3, 3] = '1';
            q.box1[3, 4] = '1';
            var numIslands = q.NumIslands(q.box1);
        }
Exemple #2
0
        public static void Main()
        {
            var obj         = new BFSQueue();
            var canParition = obj.CanPartition(new int[] { 1, 5, 11, 5 });

            var deads = new string[] { "0201", "0101", "0102", "1212", "2002" };
            var ans   = obj.OpenLock(deads, "0202");
            var rooms = new List <IList <int> >()
            {
                new List <int> {
                    1, 3
                },
                new List <int> {
                    3, 0, 1
                },
                new List <int> {
                    2
                },
                new List <int> {
                    0
                },
            };

            var canVisit = CanVisitAllRooms(rooms);

            //FloodFill
            flood       = new int[3, 3];
            flood[0, 0] = 0;
            flood[0, 1] = 0;
            flood[0, 2] = 1;
            flood[1, 0] = 1;
            flood[1, 1] = 1;
            flood[1, 2] = 1;
            flood[2, 0] = 9;
            flood[2, 1] = 4;
            flood[2, 2] = 2;
            UpdateMatrix(flood);
            flood = FloodFill(flood, 1, 1, 1);

            var q = new BFSQueue
            {
                box = new int[4, 4]
            };

            q.box[0, 0] = INFINITY;
            q.box[0, 1] = -1;
            q.box[0, 2] = 0;
            q.box[0, 3] = INFINITY;
            q.box[1, 0] = INFINITY;
            q.box[1, 1] = INFINITY;
            q.box[1, 2] = INFINITY;
            q.box[1, 3] = -1;
            q.box[2, 0] = INFINITY;
            q.box[2, 1] = -1;
            q.box[2, 2] = INFINITY;
            q.box[2, 3] = -1;
            q.box[3, 0] = 0;
            q.box[3, 1] = -1;
            q.box[3, 2] = INFINITY;
            q.box[3, 3] = INFINITY;

            q.WallsAndGates(q.box);

            q.box1       = new char[5, 5];
            q.box1[0, 0] = '1';
            q.box1[0, 1] = '1';
            q.box1[0, 2] = '0';
            q.box1[0, 3] = '0';
            q.box1[0, 4] = '0';
            q.box1[1, 0] = '1';
            q.box1[1, 1] = '1';
            q.box1[1, 2] = '0';
            q.box1[1, 3] = '0';
            q.box1[1, 4] = '0';
            q.box1[2, 0] = '0';
            q.box1[2, 1] = '0';
            q.box1[2, 2] = '1';
            q.box1[2, 3] = '0';
            q.box1[2, 4] = '0';
            q.box1[3, 0] = '0';
            q.box1[3, 1] = '0';
            q.box1[3, 2] = '0';
            q.box1[3, 3] = '1';
            q.box1[3, 4] = '1';
            var numIslands = q.NumIslands(q.box1);
        }