Challenges master

Category: Delphi -> Language/Algorithm/System Design Author: rans88 Date: 2006-07-18 02:51:10
 
rans88
2006-07-18 02:51:10
Given a two-dimensional array, arr [10] [10], which means that 100 spaces, each space can be expressed using the horizontal and vertical coordinates: wish to set (x, y)

the 100 a space, and some put a value, the number is set to m, some empty, the number is set to n;

problem: the space put a value of m classification: classification rules are: adjacent to the same category:

set up two spaces, respectively (x1, y1) and (x2, y2), "adjacent" means:

1) If x1 = x2, | y1-y2 | = 1, then the adjacent
2) If y1 = y2, | x1-x2 | = 1, then the adjacent
3) with the same space all adjacent spaces are are adjacent
[not the best recursive algorithm.]
determined the number and classification What is included in each class room?
lbinbinaoguo123
2006-07-18 03:28:13
greendragon2008 (Green Dragon), I judge that indeed also some problems, today changed look ...
baobao3355x
2006-07-18 04:02:43
Yune

wgktsj
2006-07-18 04:34:28
var
Form1: ; TForm1;
arr: array [1 .. 10,1 .. 10] of boolean;
Xarr, Yarr, Zarr: array of integer ;
Count: integer = 0;

implementation

{$ R *. dfm}

procedure TForm1.Button1Click (Sender: TObject); / / handle arrays
var I, J, K: integer;
begin
/ / ......................
if Count> 0 then
; begin
for I: = 0 to Count-1 do / / start first loop
begin
if Zarr [I ] = -1 then / / if not go to a different classification
; begin
Zarr [ I]: = memo1.Lines.Add (IntToStr (Xarr [I]) + ',' + IntToStr (Yarr [I]));
; for J: = I to Count-1 do
; begin
if Zarr [J] = -1 then
; begin
if ((Xarr [I] = Xarr [J]) and (abs (Yarr [I]-Yarr [J] ) = 1)) or ((Yarr [I] = Yarr [j]) and (abs (Xarr [I]-Xarr [J]) = 1)) then
; begin
Zarr [J]: = Zarr [I];
; Memo1.Lines [Zarr [J]]: = Memo1.Lines [Zarr [J]] + '/' + IntToStr (Xarr [J]) + ',' + IntToStr (Yarr [J])
; end;
; end
end;
end
; else
begin
for K: = I to Count-1 do
begin
if Zarr [k] = -1 then
; begin
if ((Xarr [I] = Xarr [k]) and (abs (Yarr [I]-Yarr [k]) = 1)) or ((Yarr [I] = Yarr [k]) and (abs (Xarr [I]-Xarr [k]) = 1)) then
; begin
Zarr [k]: = Zarr [I];
; Memo1.Lines [Zarr [k]]: = Memo1.Lines [Zarr [k]] + '/' + IntToStr (Xarr [k]) + ',' + IntToStr (Yarr [k])
; end;
; end
end;
end;
end;
end;
end;

procedure TForm1.Button2Click (Sender: TObject); / / put all those values ​​into an array
var I, J: integer;
begin
for I: = 1 to 10 do
begin
for J: = 1 to 10 do
begin
; if arr [I] [J] then
; begin
Inc (Count);
setLength (Xarr, Count);
setLength (Yarr, Count);
; setLength (Zarr, Count);
Xarr [Count]: = I;
Yarr [Count]: = J;
Zarr [Count]: = -1;
end;
; end;
end;
end;
------------- ------------------- non-recursive, do not look blurred vision ...
ljr8308
2006-07-18 05:01:26
one hundred units is arr [9] [9] before For ah, or is this oh arr [1 .. 10] [1 .. 10] will be right,
algorithm I do not think it can only be a recursive loop, but the reason you do not recursively What,
taige963
2006-07-18 05:40:52
1) If x1 = x2, | y1-y2 | = 1, then the adjacent
2) If y1 = y2, | x1-x2 | = 1, then the adjacent
) with the same space all adjacent spaces are not contradictory

adjacent to it? And space (0,0) adjacent to the (1,0), (0,1), (-1,0), (0, -1) is adjacent to the? So we can say the words mean that all non-empty space is adjacent to the
moshenfang
2006-07-18 06:11:08
hellolongbin (a man [I hoe Wo you when afternoon, I was steamed you are on])
-------- with the same space all adjacent spaces are adjacent (where "a space" should be understood as "a non-empty space," And your (-1,0) is also out of bounds a)
/ / / / Boss, you really fast that name, the name inside filled with a taste of the male hormone ^ - ^
canonou
2006-07-18 06:31:38
non-recursive thought for a long time have no idea, ideas always on the go to recursion, if we really want nested loops is not impossible, up to 9 can be exhausted all the neighbors, after all this is 10X10, but no universal ...
recursive should be very easy, that is found in my neighbors on the basis of the above has been looking down ... As feared grabbed wasted space, I would like to not have it.
yangkun1979
2006-07-18 06:58:07
to heluqing:
; Hello,

array, a value of the coordinates (x, y) is:
(1,5) (1,8) (1,9) (2,9) (2,5) (3,4)
(3,5) (4, 6) (5,6) (6,5) (6,6) (7,6)
(7,8) ; (7,9) (8,8) (9,8) (9,9)

your program is running, is divided into several classes?
lyfacc
2006-07-18 07:17:39
to heluqing:
using the following data in the array, a value of the coordinates (x, y) is:
(1,5) (1,8) (1,9) (2,9) (2,5) (3,4)
( 3,5) (4,6) (5,6) (6,5) (6,6) (7,6)
(7,8) (7,9) (8,8) (9,8) (9,9)

first class: 1,5 / 2,5 / 3,5
II: 1,8 / 1,9 / 2,9
third category: 3 4
..... obviously: the first category and the third category should be of the same class, but divided into two categories
zhoufeixian
2006-07-18 07:53:20
to mengyun5005:

also please you,
hands to write about,

chaiyy2006
2006-07-18 08:22:51
is such "a space" should be understood as " a non-empty space "
Sz_wei
2006-07-18 08:30:50

recursion,
has been achieved,

to non-recursive