using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; namespace SaTest { class Program { struct Structure { public float X; public float Y; } static void Main(string[] args) { var l = new Structure[2000000]; var r = new Random(); for (int i = 0; i < l.Length; i++) { l[i].X = (float)(r.NextDouble() * 1000000); l[i].Y = (float)(r.NextDouble() * 1000000); } int counter = 0; double dist = 2000; double distSquare = dist * dist; var sw = new Stopwatch(); sw.Start(); for (int i = 0; i < l.Length; i++) { for (int j = 0; j < 2000; j++) { double tx = l[i].X - l[j].X; double ty = l[i].Y - l[j].Y; if (tx * tx + ty * ty <= distSquare) //if (Math.Sqrt(tx * tx + ty * ty) <= dist) counter++; } } sw.Stop(); Console.WriteLine(counter); Console.WriteLine(sw.Elapsed); Console.ReadLine(); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)