Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            using (var prob = new CodeJamProblem("D:\\CodeJam\\test.in"))
            {
                var TestCount = prob.ReadLineInt32();

                int Count = 0;
                for (var i = 0; i < TestCount; i++)
                {
                    var Parts = prob.ReadParts();

                    BigInteger r;
                    BigInteger t;
                    BigInteger n = 0;

                    if (BigInteger.TryParse(Parts[0], out r) && BigInteger.TryParse(Parts[1], out t))
                    {
                        BigInteger S1 = 2 * r + 1;
                        BigInteger D  = (S1 - 2);
                        D = D * D + 8 * t;

                        var vSqrt = Sqrt1(D);

                        n = (-(S1 - 2) + Sqrt1(D)) / 4;
                    }
                    else
                    {
                        Count = -10000000;
                    }

                    prob.OutputCase(n);
                }
            }
        }
Ejemplo n.º 2
0
Archivo: 8.cs Proyecto: qifanyyy/CLCDSA
 static void Main(string[] args)
 {
     using (var prob = new CodeJamProblem('a', ProblemType.Large, 0))
     {
         int t = prob.ReadLineInt32();
         for (int cases = 0; cases < t; cases++)
         {
             string[] cur = prob.ReadParts();
             int      n   = int.Parse(cur[0]);
             for (int i = 0; i < n; i++)
             {
                 if (cur[2 * i + 1].Equals("O"))
                 {
                     cur[2 * i + 1] = "0";
                 }
                 else
                 {
                     cur[2 * i + 1] = "1";
                 }
             }
             int[] time = new int[2];
             int[] last = new int[2] {
                 1, 1
             };
             for (int i = 0; i < n; i++)
             {
                 int x = int.Parse(cur[2 * i + 1]);
                 int p = int.Parse(cur[2 * i + 2]);
                 time[x] += Math.Abs(p - last[x]) + 1;
                 if (time[x] < time[1 - x] + 1)
                 {
                     time[x] = time[1 - x] + 1;
                 }
                 last[x] = p;
             }
             prob.OutputCase(Math.Max(time[0], time[1]));
         }
     }
 }
Ejemplo n.º 3
0
Archivo: 8.cs Proyecto: qifanyyy/CLCDSA
    static void Main(string[] args)
    {
        using (var prob = new CodeJamProblem('b', ProblemType.Large, 0))
        {
            int t = prob.ReadLineInt32();
            for (int cases = 0; cases < t; cases++)
            {
                int[,] combine = new int[26, 26];
                for (int i = 0; i < 26; i++)
                {
                    for (int j = 0; j < 26; j++)
                    {
                        combine[i, j] = -1;
                    }
                }

                bool[,] oppo = new bool[26, 26];

                string[] cur      = prob.ReadParts();
                int      ncombine = int.Parse(cur[0]);
                int      ind      = 1;
                for (int i = 0; i < ncombine; i++)
                {
                    int x = cur[ind][0] - 'A';
                    int y = cur[ind][1] - 'A';
                    int z = cur[ind][2] - 'A';
                    combine[x, y] = combine[y, x] = z;
                    ind++;
                }
                int noppo = int.Parse(cur[ind++]);
                for (int i = 0; i < noppo; i++)
                {
                    int x = cur[ind][0] - 'A';
                    int y = cur[ind][1] - 'A';
                    oppo[x, y] = oppo[y, x] = true;
                    ind++;
                }
                int         len   = int.Parse(cur[ind++]);
                Stack <int> stack = new Stack <int>();
                foreach (char c in cur[ind])
                {
                    int x = c - 'A';
                    if (stack.Count == 0)
                    {
                        stack.Push(x);
                        continue;
                    }
                    if (combine[x, stack.Peek()] != -1)
                    {
                        int y = stack.Pop();
                        stack.Push(combine[x, y]);
                        continue;
                    }

                    bool found = false;
                    for (int i = 0; i < 26; i++)
                    {
                        if (oppo[x, i] && stack.Contains(i))
                        {
                            found = true;
                            stack.Clear();
                            break;
                        }
                    }
                    if (!found)
                    {
                        stack.Push(x);
                    }
                }
                string ans = "[";
                int[]  s   = stack.ToArray();
                for (int i = s.Length - 1; i >= 0; i--)
                {
                    ans += (char)(s[i] + 'A');
                    if (i > 0)
                    {
                        ans += ", ";
                    }
                }
                ans += "]";
                prob.OutputCase(ans);
            }
        }
    }