# [研究]不规则坐标（可看作二维数组）分组算法。欢迎所有有兴趣研究算法的人。该如何解决

www.MyException.Cn  网友分享于：2013-03-07  浏览：54次
[研究]不规则坐标（可看作二维数组）分组算法。欢迎所有有兴趣研究算法的人。

……

Point[] Group1 = {{163,83},{164,83},{163,84},{164,84},{163,85},{164,85}}
Point[] Group2 = {{197,83},{198,83},{197,84},{198,84},{197,85},{198,85}}
……

------解决方案--------------------

------解决方案--------------------

------解决方案--------------------

C# code
`public partial class Form1 : Form  {    public Form1()    {      InitializeComponent();    }      private void Form1_Paint(object sender, PaintEventArgs e)    {      int gridSize = 20;      for (int i = 0; i * gridSize  < ClientSize.Width; i++)      {        e.Graphics.DrawString(i.ToString("00"), Font, Brushes.Black,          i * gridSize - 5, 0);        e.Graphics.DrawLine(Pens.Gray, i * gridSize, gridSize,          i * gridSize, ClientSize.Height);      }      for (int i = 0; i * gridSize  < ClientSize.Height; i++)      {        e.Graphics.DrawString(i.ToString("00"), Font, Brushes.Black, 0,          i * gridSize - 5);        e.Graphics.DrawLine(Pens.Gray, gridSize, i * gridSize,          ClientSize.Width, i * gridSize);      }        for (int i = 0; i  < points.Length; i++)        e.Graphics.DrawEllipse(Pens.Red,          (points[i].X + 1) * gridSize - 3, (points[i].Y + 1) * gridSize - 3,          6, 6);        for (int i = 0; i  < groups.Count; i++)      {        int minX = int.MaxValue, minY = int.MaxValue,           maxX = int.MinValue, maxY = int.MinValue;        for (int j = 0; j  < groups[i].Count; j++)        {          Point p = groups[i][j];          minX = p.X  < minX ? p.X : minX;          minY = p.Y  < minY ? p.Y : minY;          maxX = p.X > maxX ? p.X : maxX;          maxY = p.Y > maxY ? p.Y : maxY;        }        Rectangle r = Rectangle.FromLTRB(          (minX + 1) * gridSize - 5, (minY + 1) * gridSize - 5,          (maxX + 1) * gridSize + 5, (maxY + 1) * gridSize + 5);        e.Graphics.DrawRectangle(Pens.Blue, r);        e.Graphics.DrawString(i.ToString(), Font, Brushes.Black, r);      }    }      private const int pointCount = 100;    private Point[] points = new Point[pointCount];    private bool[] scans; // 是否计算过    private List <List <Point>> groups = new List <List <Point>>();   `