当前位置: 首页>>代码示例>>C#>>正文


C# Vector2D.Select方法代码示例

本文整理汇总了C#中Vector2D.Select方法的典型用法代码示例。如果您正苦于以下问题:C# Vector2D.Select方法的具体用法?C# Vector2D.Select怎么用?C# Vector2D.Select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Vector2D的用法示例。


在下文中一共展示了Vector2D.Select方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        public static void Main(string[] args)
        {
            // n, m, and l (1 <= n,m <= 10^5, 1 <= l <= 10^9),
            // the number of squares, the number of points and the side length of each square.
            var split = Console.ReadLine().Split(' ');
            int n = Convert.ToInt32(split[0]);
            int m = Convert.ToInt32(split[1]);
            int l = Convert.ToInt32(split[2]);

            // Read in Squares
            var squares = new Vector2D[n];
            for (int i = 0; i < n; i++)
            {
                var coords = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
                squares[i] = new Vector2D(coords[0], coords[1]);
            }

            // Read in Points
            var points = new Vector2D[m];
            for (int i = 0; i < m; i++)
            {
                var coords = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
                points[i] = new Vector2D(coords[0], coords[1]);
            }

            // Find the Point that is contained in the maximum amount of squares
            // Return the maximum number of squares
            // Bruteforce: Worstcase (n * m) => 10^10
            // TODO: Bruteforce solutions is to slow for the contest, lead to timeout

            /* Linq Solution */
            int max = points.Select(p => squares.Count(s => Contains(s, l, p))).Max();

            /* Parallel Solution
            int[] res = new int[m];
            Parallel.ForEach(Partitioner.Create(0, m), (range) => {
                for (int i = range.Item1; i < range.Item2; i++) { res[i] = squares.Count(s => Contains(s, l, points[i])); }
            });
            int max = res.Max();
            */

            Console.WriteLine(max);
        }
开发者ID:joshimoo,项目名称:Challenges,代码行数:43,代码来源:SquaresAndPoints.cs


注:本文中的Vector2D.Select方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。