示例#1
0
        public void Solve(ConsoleInput cin)
        {
            var min = 30;

            var N = cin.ReadInt;

            for (int i = 0; i < N; ++i)
            {
                var A = cin.ReadInt;
                var c = 0;
                //??????????1bit????????
                while (A % 2 == 0 && A != 0)
                {
                    A >>= 1; ++c;
                }

                //??????
                min = Min(min, c);
            }
            WriteLine(min);
        }
示例#2
0
        public void Solve(ConsoleInput cin)
        {
            var N = cin.ReadInt;
            var M = cin.ReadInt;

            long[] a = new long[N];
            long[] b = new long[N];
            long[] c = new long[M];
            long[] d = new long[M];

            for (int i = 0; i < N; i++)
            {
                a[i] = cin.ReadLong;
                b[i] = cin.ReadLong;
            }
            for (int i = 0; i < M; i++)
            {
                c[i] = cin.ReadLong;
                d[i] = cin.ReadLong;
            }

            long minDist;
            int  ans;

            for (int i = 0; i < N; i++)
            {
                minDist = (long)Pow(10, 8) * 5;
                ans     = 0;
                for (int j = 0; j < M; j++)
                {
                    long dist = Abs(a[i] - c[j]) + Abs(b[i] - d[j]);
                    if (dist < minDist)
                    {
                        minDist = dist;
                        ans     = j;
                    }
                }
                WriteLine(ans + 1);
            }
        }
示例#3
0
        public void Solve(ConsoleInput cin)
        {
            // ????????
            var b = cin.ReadLine;

            if (b == "A")
            {
                WriteLine("T");
            }
            if (b == "T")
            {
                WriteLine("A");
            }
            if (b == "C")
            {
                WriteLine("G");
            }
            if (b == "G")
            {
                WriteLine("C");
            }
        }
示例#4
0
        public void Solve(ConsoleInput cin)
        {
            var X = cin.ReadInt;
            var Y = cin.ReadInt;
            var Z = cin.ReadInt;

            var num = 0;

            while (true)
            {
                if (Y * num + Z * (num + 1) > X)
                {
                    break;
                }
                else
                {
                    num++;
                }
            }

            WriteLine(num - 1);
        }
示例#5
0
        public void Solve(ConsoleInput cin)
        {
            var N = cin.ReadInt;
            var A = cin.ReadInt;
            var B = cin.ReadInt;

            /*
             * var ans = 0;
             * for(int i=1; i<=N; i++){
             *  var sum = i.ToString().Select(x => (int)(x - '0')).Sum();
             *  if(A <= sum && sum <= B)
             *      ans += i;
             * }
             */

            var ans = Enumerable.Range(1, N).Where(n => {
                var sum = n.ToString().Sum(c => (int)(c - '0'));
                return(A <= sum && sum <= B);
            }).Sum();

            WriteLine(ans);
        }
示例#6
0
        public void Solve(ConsoleInput cin)
        {
            // ????????
            var N   = cin.ReadInt;
            var A   = cin.ReadInt;
            var B   = cin.ReadInt;
            var ans = 0;

            for (var n = 1; n <= N; n++)
            {
                var sum = 0;
                foreach (var c in n.ToString())
                {
                    sum += (int)(c - '0');
                }
                if (A <= sum && sum <= B)
                {
                    ans += n;
                }
            }
            WriteLine(ans);
        }
示例#7
0
        public void Solve(ConsoleInput cin)
        {
            var N = cin.ReadInt;
            var K = cin.ReadInt;
            var x = cin.ReadIntArray(N);

            var ans = 0;

            for (int i = 0; i < N; i++)
            {
                if (x[i] < K - x[i])
                {
                    ans += 2 * x[i];
                }
                else
                {
                    ans += 2 * (K - x[i]);
                }
            }

            WriteLine(ans);
        }
示例#8
0
        void Solve(ConsoleInput cin)
        {
            int n = cin.ReadInt;
            List <Tuple <int, int> > ans = new List <Tuple <int, int> >();

            for (int i = 1; i <= n; i++)
            {
                for (int j = i + 1; j <= n; j++)
                {
                    if (n - i + ((n + 1) % 2) != j)
                    {
                        ans.Add(new Tuple <int, int>(i, j));
                    }
                }
            }

            Console.WriteLine(ans.Count);
            for (int i = 0; i < ans.Count; i++)
            {
                Console.WriteLine(ans[i].Item1 + " " + ans[i].Item2);
            }
        }
示例#9
0
        public void Solve(ConsoleInput cin)
        {
            var W = cin.ReadInt;
            var a = cin.ReadInt;
            var b = cin.ReadInt;

            if (a + W < b)
            {
                WriteLine(b - (a + W));
                return;
            }
            else if (b + W < a)
            {
                WriteLine(a - (b + W));
                return;
            }
            else
            {
                WriteLine("0");
                return;
            }
        }
示例#10
0
        public void Solve(ConsoleInput cin)
        {
            // 解答はココに書く
            var s = cin.ReadLine;

            var count0 = 0;
            var count1 = 0;

            for (var i = 0; i < s.Length; i++)
            {
                var temps = s.Substring(i, 1);
                if (i % 2 == 0)
                {
                    if (temps == "0")
                    {
                        count0++;
                    }
                    else
                    {
                        count1++;
                    }
                }
                else
                {
                    if (temps == "0")
                    {
                        count1++;
                    }
                    else
                    {
                        count0++;
                    }
                }
            }
            var ans = count0 < count1 ? count0 : count1;

            WriteLine(ans);
        }
示例#11
0
        public void Solve(ConsoleInput cin)
        {
            int n = cin.ReadInt;
            int m = cin.ReadInt;

            PrimeFactor        pf     = new PrimeFactor();
            IEnumerable <long> primes = pf.Enumerate(m);

            Dictionary <int, int> map = new Dictionary <int, int>();

            int max_r = 1;

            foreach (int num in primes)
            {
                if (map.ContainsKey(num))
                {
                    map[num]++;
                    if (max_r < map[num])
                    {
                        max_r = map[num];
                    }
                }
                else
                {
                    map[num] = 1;
                }
            }

            Modulo modulo = new Modulo(n + max_r);
            int    result = 1;

            foreach (int r in map.Values)
            {
                result = modulo.Mul(result, modulo.Ncr(n + r - 1, r));
            }

            Console.WriteLine(result);
        }
示例#12
0
        public void Solve(ConsoleInput cin)
        {
            var        FirstLine  = cin.ReadLine.Split(' ');
            int        N          = int.Parse(FirstLine[0]);
            int        Q          = int.Parse(FirstLine[1]);
            var        S          = cin.ReadLine;
            List <int> resultList = new List <int>();

            List <int> targetSums = new List <int>();
            int        len        = S.Length;
            int        ATcounter  = 0;

            for (int i = 0; i < len; i++)
            {
                targetSums.Add(ATcounter);
                if (len - 1 == i)
                {
                    break;
                }
                if (S[i] == 'A' && S[i + 1] == 'C')
                {
                    ++ATcounter;
                }
            }
            for (int i = 0; i <= Q - 1; i++)
            {
                var temp    = cin.ReadLine.Split(' ');
                int l       = int.Parse(temp[0]);
                int r       = int.Parse(temp[1]);
                var tempStr = targetSums[r - 1] - targetSums[l - 1];

                resultList.Add(tempStr);
            }
            foreach (var result in resultList)
            {
                Console.WriteLine(result);
            }
        }
示例#13
0
        public void Solve(ConsoleInput cin)
        {
            var S = cin.ReadLine;

            var  len = S.Length;
            long ans = 0;

            for (int mask = 0; mask < 1 << len - 1; mask++)
            {
                long x = 0;
                for (int i = 0; i < len; i++)
                {
                    x = x * 10 + S[i] - '0';
                    if (i == len - 1 || (mask >> i & 1) == 1)
                    {
                        ans += x;
                        x    = 0;
                    }
                }
            }

            WriteLine(ans);
        }
示例#14
0
        public void Solve(ConsoleInput cin)
        {
            //var one = cin.ReadLine.Split(' ');
            //var A = int.Parse(one[0]);
            //var B = int.Parse(one[1]);
            //var K = int.Parse(one[2]);

            var S    = cin.ReadLine;
            var zero = S.Where(x => x == '0');
            var one  = S.Where(x => x == '1');

            int result = 0;

            if (zero.Count() - one.Count() > 0)
            {
                result = one.Count() * 2;
            }
            else
            {
                result = zero.Count() * 2;
            }
            Console.Write(result);
        }
示例#15
0
        public void Solve(ConsoleInput cin)
        {
            var S = cin.ReadLine;

            var sCount = S.Count() - 2;

            int result = 1000000;
            int level  = 753;

            for (int i = 0; i < sCount; i++)
            {
                var strNum  = S[i].ToString() + S[i + 1].ToString() + S[i + 2].ToString();
                int tempVal = 0;
                int.TryParse(strNum, out tempVal);
                int dif = Math.Abs(level - tempVal);
                if (result > dif)
                {
                    result = dif;
                }
            }

            Console.Write(result);
        }
示例#16
0
        public void Solve(ConsoleInput cin)
        {
            var n = cin.ReadIntArray(3);

            int a = 0;

            foreach (var item in n)
            {
                a = (a < item) ? item: a;
            }
            var s = 1;

            foreach (var item in n)
            {
                if (item != a)
                {
                    s *= item;
                }
            }
            s /= 2;

            Console.WriteLine(s);
        }
示例#17
0
        public void Solve(ConsoleInput cin)
        {
            var one = cin.ReadLine.Split(' ');
            var N   = int.Parse(one[0]);
            var M   = long.Parse(one[1]);

            long result             = 0;
            List <List <long> > set = new List <List <long> >();

            for (int i = 0; i < N; i++)
            {
                List <long> setIn = new List <long>();
                var         two   = cin.ReadLine.Split(' ');
                setIn.Add(long.Parse(two[0]));
                setIn.Add(long.Parse(two[1]));
                set.Add(setIn);
            }
            set = set.OrderBy(x => x[0]).ToList();
            foreach (var item in set)
            {
                if (M == 0)
                {
                    break;
                }
                if (M - item[1] > 0)
                {
                    result += (item[0] * item[1]);
                    M      -= item[1];
                }
                else
                {
                    result += (item[0] * M);
                    M       = 0;
                }
            }
            Console.Write(result);
        }
示例#18
0
        public void Solve(ConsoleInput cin)
        {
            // ????????
            var n  = cin.ReadInt;
            var m  = cin.ReadInt;
            var ab = new List <dynamic>();

            for (var i = 0; i < n; i++)
            {
                var a = cin.ReadInt;
                var b = cin.ReadInt;
                ab.Add(new { a = a, b = b });
            }

            ab = ab.OrderBy(t => t.a).ToList();
            long total = 0;
            long left  = m;

            for (var i = 0; i < n; i++)
            {
                long unit = ab[i].a;
                long num  = ab[i].b;

                if (left < num)
                {
                    total += unit * left;
                    break;
                }
                else
                {
                    total += unit * num;
                    left  -= num;
                }
            }
            WriteLine(total);
        }
示例#19
0
        public void Solve(ConsoleInput cin)
        {
            var n    = cin.ReadInt;
            int maxi = 0;
            int sum  = 0;

            for (int i = 0; i < n; i++)
            {
                var l = cin.ReadInt;
                sum += l;
                maxi = Max(maxi, l);
            }
            sum -= maxi;
            if (sum > maxi)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }

            return;
        }
示例#20
0
        public void Solve(ConsoleInput cin)
        {
            // ????????
            var N = cin.ReadInt;
            var a = cin.ReadIntArray(N);

            Array.Sort(a);
            Array.Reverse(a);
            var alice = 0;
            var bob   = 0;

            for (int i = 0; i < N; ++i)
            {
                if (i % 2 == 0)
                {
                    alice += a[i];
                }
                else
                {
                    bob += a[i];
                }
            }
            WriteLine(alice - bob);
        }
示例#21
0
        public void Solve(ConsoleInput cin)
        {
            int n = cin.ReadInt;
            int m = cin.ReadInt;

            int  max = (int)Math.Ceiling(m / (double)n);
            long ans = 0;

            for (long i = 1; i <= max; i++)
            {
                if (m % i == 0)
                {
                    long div = m / i;

                    if (div % n == 0)
                    {
                        i *= div / n;
                    }
                    ans = i;
                }
            }

            Console.WriteLine(ans);
        }
示例#22
0
        public void Solve(ConsoleInput cin)
        {
            int N, M;

            N = cin.ReadInt;
            M = cin.ReadInt;
            int[] res = new int[M];
            for (int i = 0; i < M; i++)
            {
                res[i] = 1;
            }
            for (int i = 0; i < N; i++)
            {
                int    K      = cin.ReadInt;
                int [] nowres = new int[M];
                for (int j = 0; j < M; j++)
                {
                    nowres[j] = 0;
                }
                for (int j = 0; j < K; j++)
                {
                    int A = cin.ReadInt;
                    nowres[A - 1] = 1;
                }
                for (int j = 0; j < M; j++)
                {
                    if (res[j] == 1 && nowres[j] == 0)
                    {
                        res[j] = 0;
                    }
                }
            }
            int finres = Array.FindAll(res, x => x == 1).Length;

            Console.WriteLine("{0}", finres);
        }
示例#23
0
        public void Solve(ConsoleInput cin)
        {
            // ????????
            var n = cin.ReadInt;
            var a = cin.ReadInt;
            var b = cin.ReadInt;

            var result = 0;

            for (var i = 0; i <= n; i++)
            {
                var istr = i.ToString();
                var val  = 0;
                foreach (var s in istr)
                {
                    val += int.Parse(s.ToString());
                }
                if (a <= val && val <= b)
                {
                    result += i;
                }
            }
            WriteLine(result);
        }
示例#24
0
        public void Solve(ConsoleInput cin)
        {
            var s = cin.Read;

            WriteLine(s.Count(x => x == '1'));
        }
示例#25
0
 public void Solve(ConsoleInput cin)
 {
 }