コード例 #1
0
ファイル: 6.cs プロジェクト: qifanyyy/CLCDSA
        public string SolveOneCase(InputParser input)
        {
            int K = input.GetInt();
            int L = input.GetInt();
            int S = input.GetInt();

            string alph = input.GetString();
            string word = input.GetString();

            // not in alphabet
            for (int i = 0; i < L; i++)
            {
                var c = word[i];
                if (!alph.Contains(c.ToString()))
                {
                    return("0.0");
                }
            }

            // all same
            bool same = true;
            var  a    = word[0];

            for (int i = 0; i < L; i++)
            {
                if (word[i] != a)
                {
                    same = false;
                }
            }
            for (int i = 0; i < K; i++)
            {
                if (alph[i] != a)
                {
                    same = false;
                }
            }

            if (same)
            {
                return("0.0");
            }

            int overlap = 0;

            for (int i = 1; i < L; i++)
            {
                var st = word.Substring(0, i);
                var e  = word.Substring(word.Length - i, i);

                if (st == e)
                {
                    overlap = i;
                }
            }

            int count = 0;
            int ii    = 0;

            while (true)
            {
                if (ii + L <= S)
                {
                    count++;
                    ii = ii + L - overlap;
                    continue;
                }
                break;
            }

            double p = 1;

            for (int i = 0; i < L; i++)
            {
                var    aa = word[i];
                double cc = alph.Count(x => x == aa);
                p *= cc / K;
            }

            var res = count - p * (S - L + 1);


            return(res.ToString());
        }
コード例 #2
0
ファイル: 2.cs プロジェクト: qifanyyy/CLCDSA
        public string SolveOneCase(InputParser input)
        {
            int X = input.GetInt();
            int Y = input.GetInt();


            int sum = Math.Abs(X) + Math.Abs(Y);

            int n    = 1;
            int nsum = 0;

            while (true)
            {
                nsum += n;

                if (nsum % 2 == sum % 2)
                {
                    if (nsum >= sum)
                    {
                        break;
                    }
                }

                n++;
            }

            StringBuilder sb = new StringBuilder();

            for (int i = n; i > 0; i--)
            {
                if (Math.Abs(X) >= Math.Abs(Y))
                {
                    if (X < 0)
                    {
                        sb.Append('W');
                        X += i;
                    }
                    else
                    {
                        sb.Append('E');
                        X -= i;
                    }
                }
                else
                {
                    if (Y < 0)
                    {
                        sb.Append('S');
                        Y += i;
                    }
                    else
                    {
                        sb.Append('N');
                        Y -= i;
                    }
                }

                //Console.WriteLine((String.Format("X={0} Y={1}", X, Y)));
            }

            if (X != 0 && Y != 0)
            {
                throw new Exception(String.Format("X={0} Y={1}", X, Y));
            }

            var s   = sb.ToString();
            var car = s.ToCharArray();

            Array.Reverse(car);

            return(new string(car));
        }