예제 #1
0
        static void MinAvgTwoSlice()
        {
            int[] A = new int[] { -46, 30, 76, 87, -14, 79, 31, 1, 75, -73, -28, -4, -68, -53, 36, -46, -75, -4, 85, -87 };

            // A = Generator.MinAvgTwoSlice1(10,-10000,10000);

            result   r;
            TimeSpan t;
            DateTime st, end;

            WriteLine("[{0}]", string.Join(", ", A));

            MinAvgTwoSlice minavg = new MinAvgTwoSlice();

            st  = DateTime.Now;
            r   = minavg.solution(A);
            end = DateTime.Now;
            t   = end - st;
            WriteLine($"Solution   Index:{r.index} Slice:{r.slice} Average:{r.average} Time:{t}");

            st  = DateTime.Now;
            r   = minavg.solution1(A);
            end = DateTime.Now;
            t   = end - st;
            WriteLine($"Solution1  Index:{r.index} Slice:{r.slice} Average:{r.average} Time:{t}");

            st  = DateTime.Now;
            r   = minavg.solution2(A);
            end = DateTime.Now;
            t   = end - st;
            WriteLine($"Solution2  Index:{r.index} Slice:{r.slice} Average:{r.average} Time:{t}");
        }
예제 #2
0
        static void MinAvgTwoSliceWhile()
        {
            int[] A = new int[] { 744, -8387, 9068, -8279, 2064, 22, -5427, 4865, -3048, -2723 };

            result   r, r1, r2;
            TimeSpan t, t1, t2;
            DateTime st, end;
            bool     stop  = false;
            int      count = 0;



            MinAvgTwoSlice minavg = new MinAvgTwoSlice();

            while (!stop)
            {
                A = Generator.MinAvgTwoSlice1(200, -1000, 1000);


                st  = DateTime.Now;
                r   = minavg.solution(A);
                end = DateTime.Now;
                t   = end - st;

                st  = DateTime.Now;
                r1  = minavg.solution1(A);
                end = DateTime.Now;
                t1  = end - st;

                st  = DateTime.Now;
                r2  = minavg.solution2(A);
                end = DateTime.Now;
                t2  = end - st;

                if (r.index != r1.index || r.index != r2.index || count == 1000)
                {
                    WriteLine("[{0}]", string.Join(", ", A));
                    WriteLine($"Time: {t}   solution   :{r.index} ");
                    WriteLine($"Time: {t1}   solution2   :{r1.index} ");
                    WriteLine($"Time: {t2}   solution2   :{r2.index} ");

                    //stop = true;
                    count = 0;
                    ConsoleKeyInfo i = ReadKey();
                    if (i.KeyChar == 's')
                    {
                        stop = true;
                    }
                }
                // WriteLine("Time: {0}    solution   :{1} ", sol, result);
                count++;
            }
        }
예제 #3
0
        static void FindSlice()
        {
            int[]          A      = Generator.MinAvgTwoSlice1(10000, -1, 1);
            MinAvgTwoSlice minavg = new MinAvgTwoSlice();
            result         res    = new result {
                index = 0, slice = 2
            };
            int i = 0;

            do
            {
                A   = Generator.MinAvgTwoSlice1(1000, -10000, 10000);
                res = minavg.solution2(A);
                if (i > 100 || res.slice > 3)
                {
                    //WriteLine("[{0}]", string.Join(", ", A));
                    WriteLine("index:{0}   slice:{1} ", res.index, res.slice);
                    i = 0;
                }


                i++;
            } while (true);
        }