Exemplo n.º 1
0
            public void calc()
            {
                Console.WriteLine();
                ok     = new bool[N];
                nokori = 2 * N;
                bool ng = false;

                box = new int[H, W];

                BIT bit = new BIT(nokori + 2);

                for (int i = 0; i < nokori; i++)
                {
                    bit.bitUpdate(i + 1, 1);
                }

                while (nokori > 0)
                {
                    bool flag = false;
                    for (int i = 0; i < N; i++)
                    {
                        if (ok[i])
                        {
                            continue;
                        }
                        int count = bit.bitCal(B[i], A[i]);
                        //Console.WriteLine("count " + i + " " + count);
                        if (count == 2)
                        {
                            //Console.WriteLine("start " + i);
                            //時計周り
                            if (!connect(A[i], B[i]))
                            {
                                ng = true;
                                break;
                            }
                            nokori -= 2;
                            bit.bitUpdate(A[i], -1);
                            bit.bitUpdate(B[i], -1);
                            flag  = true;
                            ok[i] = true;
                            //Console.WriteLine("OK " + i);
                        }
                        else if (count == nokori)
                        {
                            //Console.WriteLine("start " + i);
                            //反時計周り
                            if (!connect(B[i], A[i]))
                            {
                                ng = true;
                                break;
                            }
                            nokori -= 2;
                            bit.bitUpdate(A[i], -1);
                            bit.bitUpdate(B[i], -1);
                            flag  = true;
                            ok[i] = true;
                            //Console.WriteLine("OK " + i);
                        }
                    }

                    if (!flag || ng)
                    {
                        Console.WriteLine("IMPOSSIBLE");
                        return;
                    }
                }
                for (int i = 0; i < H; i++)
                {
                    for (int j = 0; j < W; j++)
                    {
                        Console.Write(memo[box[i, j]]);
                    }
                    Console.WriteLine();
                }
            }