コード例 #1
0
ファイル: 8.cs プロジェクト: qifanyyy/CLCDSA
    static void Main(string[] args)
    {
        using (var prob = new CodeJamProblem('c', ProblemType.Large, 0))
        {
            int t = prob.ReadLineInt32();
            for (int cases = 0; cases < t; cases++)
            {
                int   n   = prob.ReadLineInt32();
                int   ans = 0;
                int[] f   = prob.ReadInt32Array();

                int min = 10000000;
                int sum = 0;
                foreach (int x in f)
                {
                    ans  = (ans ^ x);
                    sum += x;
                    if (min > x)
                    {
                        min = x;
                    }
                }
                if (ans != 0)
                {
                    prob.OutputCase("NO");
                }
                else
                {
                    prob.OutputCase(sum - min);
                }
            }
        }
    }
コード例 #2
0
    static void Main(string[] args)
    {
        using (var prob = new CodeJamProblem('d', ProblemType.Large, 0))
        {
            int t = prob.ReadLineInt32();
            for (int cases = 0; cases < t; cases++)
            {
                int   n   = prob.ReadLineInt32();
                int   ans = 0;
                int[] f   = prob.ReadInt32Array();

                for (int i = 0; i < n; i++)
                {
                    if (f[i] != i + 1)
                    {
                        ans++;
                    }
                }
                prob.OutputCase(ans.ToString() + ".000000");
            }
        }
    }
コード例 #3
0
ファイル: 0.cs プロジェクト: qifanyyy/CLCDSA
 static void Main(string[] args)
 {
     using (var prob = new CodeJamProblem('a', ProblemType.Large, 0))
     {
         int tcase = prob.ReadLineInt32();
         for (int cases = 0; cases < tcase; cases++)
         {
             int[]    a  = prob.ReadInt32Array();
             int      r  = a[0];
             int      c  = a[1];
             string[] ss = prob.ReadLines(r);
             char[,] s = new char[r, c];
             for (int i = 0; i < r; i++)
             {
                 for (int j = 0; j < c; j++)
                 {
                     s[i, j] = ss[i][j];
                 }
             }
             bool ok = true;
             for (int i = 0; i < r; i++)
             {
                 for (int j = 0; j < c; j++)
                 {
                     if (s[i, j] == '#')
                     {
                         if (i == r - 1 || j == c - 1)
                         {
                             ok = false;
                             break;
                         }
                         if (s[i + 1, j] != '#' || s[i, j + 1] != '#' || s[i + 1, j + 1] != '#')
                         {
                             ok = false;
                             break;
                         }
                         s[i, j]         = '/';
                         s[i, j + 1]     = '\\';
                         s[i + 1, j]     = '\\';
                         s[i + 1, j + 1] = '/';
                     }
                     if (!ok)
                     {
                         break;
                     }
                 }
                 if (!ok)
                 {
                     break;
                 }
             }
             prob.OutputCase();
             if (!ok)
             {
                 prob.WriteLine("Impossible");
             }
             else
             {
                 for (int i = 0; i < r; i++)
                 {
                     string ans = "";
                     for (int k = 0; k < c; k++)
                     {
                         ans += s[i, k];
                     }
                     prob.WriteLine(ans);
                 }
             }
         }
     }
 }
コード例 #4
0
ファイル: 20.cs プロジェクト: qifanyyy/CLCDSA
    static void Main(string[] args)
    {
        using (var prob = new CodeJamProblem('a', ProblemType.Large, 1))
        {
            var t = prob.ReadLineInt32();
            for (int c = 0; c < t; c++)
            {
                var info1 = prob.ReadInt32Array();
                var n     = info1[0];
                var k     = info1[1];
                var board = prob.ReadLines(n).Select(s => s.Select(ch => ".RB".IndexOf(ch)).ToArray()).ToArray();

                for (int i = 0; i < board.Length; i++)
                {
                    for (int r = 0; r < board[i].Length - 1; r++)
                    {
                        for (int j = board[i].Length - 1; j >= 1; j--)
                        {
                            if (board[i][j] == 0)
                            {
                                board[i][j]     = board[i][j - 1];
                                board[i][j - 1] = 0;
                            }
                        }
                    }
                }

                var red  = false;
                var blue = false;
                for (int i = 0; i < board.Length; i++)
                {
                    for (int j = 0; j < board[i].Length; j++)
                    {
                        var p = board[i][j];
                        if (p == 0)
                        {
                            continue;
                        }

                        var hl  = true;
                        var vl  = true;
                        var dll = true;
                        var drl = true;

                        for (int x = 1; x < k; x++)
                        {
                            if (j <= board[i].Length - k)
                            {
                                if (board[i][j + x] != p)
                                {
                                    hl = false;
                                }
                            }
                            else
                            {
                                hl = false;
                            }

                            if (i >= k - 1 && j <= board[i].Length - k)
                            {
                                if (board[i - x][j + x] != p)
                                {
                                    dll = false;
                                }
                            }
                            else
                            {
                                dll = false;
                            }

                            if (i <= board.Length - k)
                            {
                                if (board[i + x][j] != p)
                                {
                                    vl = false;
                                }
                            }
                            else
                            {
                                vl = false;
                            }

                            if (i <= board.Length - k && j <= board[i].Length - k)
                            {
                                if (board[i + x][j + x] != p)
                                {
                                    drl = false;
                                }
                            }
                            else
                            {
                                drl = false;
                            }
                        }

                        var hasLine = hl || vl || dll || drl;
                        if (p == 1)
                        {
                            red |= hasLine;
                        }
                        else if (p == 2)
                        {
                            blue |= hasLine;
                        }
                    }
                }

                if (red && blue)
                {
                    prob.OutputCase("Both");
                }
                else if (red)
                {
                    prob.OutputCase("Red");
                }
                else if (blue)
                {
                    prob.OutputCase("Blue");
                }
                else
                {
                    prob.OutputCase("Neither");
                }
            }
        }
    }
コード例 #5
0
ファイル: 19.cs プロジェクト: qifanyyy/CLCDSA
        static void Main(string[] args)
        {
            using (var prob = new CodeJamProblem("D:\\CodeJam\\test.in"))
            {
                var TestCount = prob.ReadLineInt32();

                for (var i = 0; i < TestCount; i++)
                {
                    prob.ReadInts(out MaxE, out R, out N);
                    AValues = prob.ReadInt32Array();
                    UsedE   = new int[N];

                    bool[] Tested     = new bool[N];
                    int    MaxGain    = 0;
                    int    MaxGainInd = -1;

                    bool Again = true;

                    while (Again)
                    {
                        Again      = false;
                        MaxGain    = 0;
                        MaxGainInd = -1;

                        for (var k = 0; k < N; k++)
                        {
                            if ((Tested[k] == false) && (AValues[k] > MaxGain))
                            {
                                MaxGainInd = k;
                                MaxGain    = AValues[k];
                            }
                        }
                        if (MaxGainInd > -1)
                        {
                            Tested[MaxGainInd] = true;
                            UsedE[MaxGainInd]  = CalcEnergy(MaxGainInd);
                            if (UsedE[MaxGainInd] > 0)
                            {
                                Again = true;
                            }
                            UsedE[MaxGainInd] -= Correct();
                            if (UsedE[MaxGainInd] > 0)
                            {
                                Again = true;
                            }
                            else
                            {
                                UsedE[MaxGainInd] = 0;
                            }
                            if (Correct() < 0)
                            {
                                Again = false;
                            }
                        }
                    }


                    int Gain = 0;
                    for (var k = 0; k < N; k++)
                    {
                        Gain += UsedE[k] * AValues[k];
                    }
                    prob.OutputCase(Gain);
                }
            }
        }