Beispiel #1
0
        private static void FastThreeSumCalc(string[] args)
        {
            if (args.Length == 0)
            {
                System.Console.WriteLine("需要在参数中指定问题规模! \n放弃计算...");
                return;
            }
            int count = int.Parse(args[0]);

            for (int i = 1; i <= 5; i++)
            {
                int size  = count * Convert.ToInt32(Math.Pow(2, i));
                var arr   = ThreeSum.GetRandomArray(size);
                var watch = new Stopwatch();
                watch.Start();
                var result = FastThreeSum.Count(arr);
                watch.Stop();
                var ts = watch.Elapsed;
                System.Console.WriteLine();
                System.Console.WriteLine($"快速-消耗时间: {ts.TotalMilliseconds} ms ({ts.TotalSeconds} s)");
                System.Console.WriteLine($"快速-问题规模: {arr.Length}");
                System.Console.WriteLine($"快速-求解结果(三个数和为 0 的个数): {result}");
                System.Console.WriteLine();
            }
        }
Beispiel #2
0
        private static void ThreeSumCalc(int count)
        {
            var arr   = ThreeSum.GetRandomArray(count);
            var watch = new Stopwatch();

            watch.Start();
            var result = ThreeSum.Count(arr);

            watch.Stop();
            var ts = watch.Elapsed;

            System.Console.WriteLine();
            System.Console.WriteLine($"消耗时间: {ts.TotalMilliseconds} ms ({ts.TotalSeconds} s)");
            System.Console.WriteLine($"问题规模: {arr.Length}");
            System.Console.WriteLine($"求解结果(三个数和为 0 的个数): {result}");
            System.Console.WriteLine();
        }
Beispiel #3
0
        private static void FastTwoSumCalc(string[] args)
        {
            if (args.Length == 0)
            {
                System.Console.WriteLine("需要在参数中指定问题规模! \n放弃计算...");
                return;
            }
            int count = int.Parse(args[0]);
            var arr   = ThreeSum.GetRandomArray(count);
            var watch = new Stopwatch();

            watch.Start();
            var result = FastTwoSum.Count(arr);

            watch.Stop();
            var ts = watch.Elapsed;

            System.Console.WriteLine($"快速两数相加: {result}, 耗时: {ts.TotalSeconds} S");
        }