コード例 #1
0
        public void TestMethod6()
        {
            //2 1 1 1
            //3 1 1 2
            //2 2 1 1

            LinkedList <Note> list = new LinkedList <Note>();
            Note note = new Note {
                Position = 2, Length = 1, Speed = 1, Score = 1
            };

            list.AddLast(note);

            note = new Note {
                Position = 3, Length = 1, Speed = 1, Score = 2
            };
            list.AddLast(note);

            note = new Note {
                Position = 2, Length = 2, Speed = 1, Score = 1
            };
            list.AddLast(note);

            var result = NoteProblem.Solve(list.ToArray());

            Assert.IsTrue(result == 2);
        }
コード例 #2
0
        public void TestMethod3()
        {
            LinkedList <Note> list = new LinkedList <Note>();

            for (int i = 0; i < 100; i++)
            {
                Note note = new Note {
                    Position = 4, Length = 2, Score = 1, Speed = 2
                };
                list.AddLast(note);
                note = new Note {
                    Position = 8, Length = 2, Score = 2, Speed = 2
                };
                list.AddLast(note);
            }
            var result = NoteProblem.MergeEquivalents(list.ToArray());

            Assert.IsTrue(result.Length == 2);
            CollectionAssert.AreEqual(result.Select(e => e.Score).ToArray(), new int[] { 100, 200 });
        }
コード例 #3
0
        public void TestMethod7()
        {
            //18 2 2 5
            //1 2 1 1
            //16 10 2 3
            //8 10 2 4
            //27 6 3 5

            LinkedList <Note> list = new LinkedList <Note>();
            Note note = new Note {
                Position = 18, Length = 2, Speed = 2, Score = 5
            };

            list.AddLast(note);

            note = new Note {
                Position = 1, Length = 2, Speed = 1, Score = 1
            };
            list.AddLast(note);

            note = new Note {
                Position = 16, Length = 10, Speed = 2, Score = 3
            };
            list.AddLast(note);

            note = new Note {
                Position = 8, Length = 10, Speed = 2, Score = 4
            };
            list.AddLast(note);

            note = new Note {
                Position = 27, Length = 6, Speed = 3, Score = 5
            };
            list.AddLast(note);

            var result = NoteProblem.Solve(list.ToArray());

            Assert.IsTrue(result == 6);
        }
コード例 #4
0
    /// <summary>
    /// Explanation :
    /// The NoteProblem class is the main class.
    /// The idea is a dynamic programming solution .
    /// If we sort the notes by the time1(that is the start arriving time ) we could see this problem
    /// like Note1 Note2 ---- NoteN and we want to obtain the MaximumScore from Note1 to the Final
    /// If We see this problem like having the set Note1 Note2 --- NoteN it could be the problem
    /// of MaximumScore from Note_i to the final with i = 1
    /// The we have a generic problem MaximumScore(i) .
    /// The MaximumScore(i) = MaximumValue( MaximumScore(selecting(Note_i)), MaximumScore(NotSelecting(Note_i));
    /// MaximumScore(selecting(Note_i)) = NoteValue_i.Score + MaximumScore(j) with j the first index Note of all the Notes that are not intersecting
    /// with Note_i
    /// MaximumScore(NotSelecting(Note_i) = MaximumScore(i+1)
    /// This algorithm is O(N*log(N)) foreach case
    /// The Total is O(C*O(N*log(N)))
    /// </summary>
    /// <param name="args"></param>
    public static void Main(string[] args)
    {
        try
        {
            int C = int.Parse(Console.ReadLine());
            for (int i = 1; i <= C; i++)
            {
                try
                {
                    int N = int.Parse(Console.ReadLine());
                    LinkedList <Note> notes = new LinkedList <Note>();
                    for (int j = 0; j < N; j++)
                    {
                        string[] stringParts = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                        int      X           = int.Parse(stringParts[0]);
                        int      L           = int.Parse(stringParts[1]);
                        int      S           = int.Parse(stringParts[2]);
                        int      P           = int.Parse(stringParts[3]);
                        notes.AddLast(new Note {
                            Position = X, Length = L, Speed = S, Score = P
                        });
                    }

                    int    result       = NoteProblem.Solve(notes.ToArray());
                    string prefixString = "Case #" + i + ": ";
                    Console.WriteLine(prefixString + result);
                }
                catch (Exception exception)
                {
                    Console.WriteLine("Case #" + i + ": ");
                    Console.WriteLine(exception);
                }
            }
        }
        catch (Exception exception)
        {
            Console.WriteLine(exception);
        }
    }