Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            List <masu> grid = new List <masu>();

            for (int x = 0; x < MASU_LENGTH; x++)
            {
                for (int y = 0; y < MASU_LENGTH; y++)
                {
                    masu temp = new masu()
                    {
                        x      = y,
                        y      = x,
                        exists = false,
                        setOK  = true
                    };

                    grid.Add(temp);
                }
            }

            for (int x = 0; x < MASU_LENGTH; x++)
            {
                string input = Console.ReadLine();
                int    y     = 0;
                foreach (var ch in input)
                {
                    int accessIndex = (x * MASU_LENGTH) + y;
                    if (ch == 'Q')
                    {
                        if (!grid[accessIndex].setOK)
                        {
                            Console.WriteLine("No Answer");
                            Console.ReadLine();
                            return;
                        }

                        grid[accessIndex].exists = true;

                        setNG(ref grid, grid[accessIndex]);
                    }
                    y++;
                }
            }

            List <masu> ansGrid = solve(grid);

            if (ansGrid == null)
            {
                Console.WriteLine("No Answer");
                Console.ReadLine();
                return;
            }

            for (int x2 = 0; x2 < MASU_LENGTH; x2++)
            {
                Console.WriteLine("{0}", string.Join("", ansGrid.Skip(x2 * MASU_LENGTH).Take(MASU_LENGTH).Select(c => c.exists ? "Q" : ".")));
            }
            Console.ReadLine();
        }
Ejemplo n.º 2
0
        static public void setNG(ref List <masu> area, masu target)
        {
            // ?
            foreach (var item in area.Select(c => c).Where(c => c.y == target.y))
            {
                item.setOK = false;
            }

            // ?
            foreach (var item in area.Select(c => c).Where(c => c.x == target.x))
            {
                item.setOK = false;
            }

            // ??
            foreach (var item in area.Select(c => c).Where(c => (Math.Abs(c.x - target.x) == Math.Abs(c.y - target.y))))
            {
                item.setOK = false;
            }
        }