Example #1
0
        public override IEnumerable <object> Solve(TextReader inputStream)
        {
            var hw     = inputStream.ReadIntArray();
            var height = hw[0];
            var width  = hw[1];
            var states = new int[height][];

            for (int row = 0; row < height; row++)
            {
                states[row] = inputStream.ReadIntArray();
            }

            var bitStates = GetBitState(states);

            int max  = 0;
            var mask = BitSet.CreateMask(height);

            for (BitSet flip = BitSet.Zero; flip < BitSet.At(height); flip++)
            {
                var count = 0;
                for (int column = 0; column < width; column++)
                {
                    var state = bitStates[column] ^ flip;
                    count += Math.Max(state.Count(), (~state & mask).Count());
                }
                max = Math.Max(max, count);
            }
            yield return(max);
        }
Example #2
0
        public override IEnumerable <object> Solve(TextReader inputStream)
        {
            var dg            = inputStream.ReadIntArray();
            var maxDifficulty = dg[0];
            var requiredScore = dg[1];
            var problems      = new int[maxDifficulty];
            var bonuses       = new int[maxDifficulty];

            for (int difficulty = 0; difficulty < maxDifficulty; difficulty++)
            {
                var pc = inputStream.ReadIntArray();
                problems[difficulty] = pc[0];
                bonuses[difficulty]  = pc[1];
            }

            var minSolved = int.MaxValue;

            for (BitSet flag = BitSet.Zero; flag < BitSet.At(maxDifficulty); flag++)
            {
                var solved = 0;
                var score  = 0;
                for (int difficulty = 0; difficulty < maxDifficulty; difficulty++)
                {
                    if (flag[difficulty])
                    {
                        score  += (difficulty + 1) * 100 * problems[difficulty] + bonuses[difficulty];
                        solved += problems[difficulty];
                    }
                }

                for (int difficulty = maxDifficulty - 1; difficulty >= 0; difficulty--)
                {
                    if (score >= requiredScore)
                    {
                        break;
                    }

                    var scorePerQuestion = (difficulty + 1) * 100;

                    if (!flag[difficulty])
                    {
                        var toSolve = Math.Min((requiredScore - score + scorePerQuestion - 1) / scorePerQuestion, problems[difficulty] - 1);
                        solved += toSolve;
                        score  += scorePerQuestion * toSolve;
                    }
                }

                if (score >= requiredScore)
                {
                    minSolved = Math.Min(minSolved, solved);
                }
            }

            yield return(minSolved);
        }