Вы находитесь на странице: 1из 15

19.

.
. 19.1 .
0

0
0
0

0
0
0

3
3
3

0
0
0

3
3

)
()

. 19.1.

. v1 > v2 ( v1 v2),
v1 v2, v2
v1.
, , .
(), , . ,
. 19.1. 1 0, 2, 3, 4, . 19.1.
4 0, 2, 3.
() .
(). ,
. 19.1. 0 2, 1 3,
4 0. . 19.1. 0 2,

4.
. .
19.1. 4.
1

(), , .
,
.
(). , . 19.1.
0 3 :
0 1 3 ( 2),
0 1 4 3 ( 3),
0 5 3 ( 2).
, () ,
. . 19.1.

01350,
014350,
1341.
()
.
.
:
1. ,
, .
2. ,
, . ,
.

.

.
,
: , , ,
..


.
1. (),
. ()
.
.
. 19.1.:
5 -
0
1
2
2
3
4
4

1
2
3
4
4
0
2
,

.
19.1.
#define
NMAX
10
/* . */
#define
RMAX
55
/* . */
/* RMAX = NMAX * (NMAX - 1) / 2 + NMAX; */
int v1 [RMAX];
/* */
int v2 [RMAX];
/*

*/
int n;
/* */
int r;
/* */
2.

n*n (n ),

1, i > j ,
ms[i][j] =
0

.
3

, . 19.1.:
|012345
----------------------------

0|010001
1|101110
2|010000
3|010011
4|010100
5|100100

19.2.
.
Ctrl Z ( ).
#define
NMAX
10
/* . */
/* */
int VvodGraf ( int ms [NMAX] [NMAX] )
/* ms */
/* */
{ int n;
/* */
int i, j; /* */
puts (\n (<=10));
scanf (%d, &n);
/* */
for (i=0; i<n; i++)
for (j=0; j<n; j++) ms[i][j] = 0;
puts ( , );
puts ( Ctrl-Z);
while (scanf(%d %d, &i,&j) !=EOF)
ms[i][j] = ms[j][i] = 1;
return n;
}
/* */
void main()
{ int g[NMAX][ NMAX] ; /* */
int n;
/* */

n = VvodGraf (g);
/* */

}
3.
4

n*n

(n

),
mw [i][j] = i > j
, : , .
.
0

0
0
0

0
0
300

50

45

60
30

100

| 0
1 2 3 4
5
-----------------------0 | 0
50 0 0 0 100
1 | 50 0
45 60 30 0
mw = 2 | 0
45 0 0 0 0
3 | 0
60 0 0 30 60
4 | 0
30 0 30 0 0
5 | 100 0
0 60 0 0

60

3
3
3

. 19.2. .
:
#define
NMAX
10
int mw[NMAX][ NMAX] ;
int n;
4.

/* . */
/* */
/* */

n*r ( n , r ).

:
mi[i][j] =

1, i- j- ,
2, j- i- ,
0, i- j- .

0
0
0

0
1
0 2
3
04
0
0
4
0
0
3 0
0
0
0

2
0

0
0
0

|0 1 2 3 4 5 6
----------------------------------

0|1
1|1
mi = 2 | 0
3|0
4|0

0
1
1
0
0

. 19.3. .
5

0
1
0
1
0

0
0
0
1
1

0
1
0
0
1

1
0
0
0
1

0
0
2
0
0

:
mi[i][j] =

-1,
1,
2,
0,

j- i- i
j- i-
j
j- i- ,
i- j- .

1
0

0
0
0

0
0
0 3

1
34
0

0
0
0

|0 1 2 3 4 5

2
0

-------------------------------

0 | -1 0 0 1 0
mi = 1 | 1 -1 0 0 1
2| 0 1 1 0 0
3 | 0 0 -1 -1 -1

0
0
0

. 19.4. .

:
#define
NMAX
10
#define
RMAX
100
int mi[NMAX][ RMAX] ;
int n;
int r;

/* . */
/* . () */
/* */
/* */
/* */

19.3.
/* */
void VivodMatrIn (int mi[NMAX][RMAX], int n, int r)
{
int i, j;
printf ( |);
for (j=0; j<r; j++) printf (%3d, j);
printf (\n);
for (j=0; j<3*r +2; j++) putchar();
for (i=0; i<n; i++)
{ printf (\n%d|, i);
for (j=0; j<r; j++)
6

0
0
0
2

printf (%3d, mi[i][j]);


}
printf (\n);
}
5. .

.
:

. 19.5. .

, i- i- .
:
#define
NMAX
10
/* . */
int vsm[NMAX][ NMAX+1] ; /* */
int n;
/* */

vsm

NMAX+1,


, -1.

vsm[i]

i- .

.
19.4.
/* */
void VectSm (int vsm[NMAX][NMAX+1], int *pn)
7

/* . : vsm ,
*pn */
{ int i, j; /* */
printf ( :);
scanf(%d, pn);
puts ( );
for (i = 0; i < *pn: i++)
{ printf (%d: , i);
j = -1;
do scanf(%d, &vsm[i][++j]);
while (vsm[i][j] != -1);
}
}
, . 19.5, (
):
: 4

0: 1 3 -1
1: 0 2 3 -1
2: 1 -1
3: 0 1 -1
/* */
int vsm[NMAX][ NMAX+1] ; /* */
int n;
/* */
VectSm ( vsm, &n);
:
| 0 1 2 3 4
-------------------0 | 1 3 -1
vsm = 1 | 0 2 3 -1
2 | 1 -1
3 | 0 1 -1
6. .
.

. 19.6. .
:
#define
NMAX
10
/* . */
/* */
struct LIST
{ int v;
/* */
struct LIST *next; /* */
};
struct LIST *p [NMAX];
/* */
int n;
/* */

19.1. n<=7
.

.
:
#include <stdio.h>
#include <conio.h>
#define NMAX 7 /* */
#define RMAX 21 /*
*/
/*---------------------------------------------------------*/
/*

*/
/*---------------------------------------------------------*/
void VVOD_MATR_SM ( int g1 [NMAX][NMAX] , int
/* : n
9

n)
*/

/* : g1 */
int i,j ; /* */
printf (" :\n\n");
printf (" ");
for (j=0; j<n; j++) printf ("%d ",j);
putchar ('\n');
for (i=0; i<2*n+2; i++) putchar ('-');
for (i=0; i<n; i++)
{ printf ("\n%d ",i);
for (j=0; j<n; j++) scanf ("%d", &g1[i][j]);
}
putchar ('\n');

}
/*------------------------------------------------------------*/
/* */
/*------------------------------------------------------------*/
void VIVOD_MATR_IN ( int g2 [NMAX][RMAX], int
/* : g2 ,
n ,
k */
{ int i,l ; /* */
printf (" \n\n");
printf (" ");
for (l=0; l<k; l++) printf ("%3d ", l );
putchar ('\n');
for (i=0; i<3*k+2; i++) putchar ('-');
for (i=0; i<n; i++)
{ printf ("\n%d ", i);
for (l=0; l<k; l++)
printf ("%3d ",g2[i][l]);
}
putchar ('\n');
}
/*------------------------------*/
/* */
/*------------------------------*/

n, int k )

void main()
{
int g1 [NMAX][NMAX] ,
/* */
g2 [NMAX][RMAX] = {0} ,
/* - */
n,
/* */
k;
/* */
int i, j; /* g1,g2 */
10

printf ("\n :");


scanf ("%d", &n);
VVOD_MATR_SM (g1, n); /* g1 */
/* - g2 */
k=0;
for (i=0; i<n; i++)
for (j=i; j<n; j++)
if (g1[i][j])
{ g2[i][k]=1;
g2[j][k]=1;
k++;
}
VIVOD_MATR_IN (g2, n, k ); /* - g2 */
getch();
}

1.

:
n=4

00

11
3

2
2
4

0 1 2 3
---------0 0 1 0 1
1 1 0 1 1
2 0 1 0 1
3 1 1 1 0

2. , . 19.1.


0 1 2 3 4
-----------0 1 1 0 0 0
1 1 0 1 1 0
2 0 0 1 0 1
3 0 1 0 1 1

n=NMAX=7.

. 19.2. :

, . 19.2.
3. ( ),
.
:

n=7,
11

:
0 1 2 3 4 5 6
---------------0 0 1 1 1 1 1 1
1 1 0 1 1 1 1 1
2 1 1 0 1 1 1 1
3 1 1 1 0 1 1 1
4 1 1 1 1 0 1 1
5 1 1 1 1 1 0 1
6 1 1 1 1 1 1 0

:
:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
----------------------------------------------------------------0 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 1 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0
2 0 1 0 0 0 0 1 0 0 0 0 1 1 1 1 0 0 0 0 0 0
3 0 0 1 0 0 0 0 1 0 0 0 1 0 0 0 1 1 1 0 0 0
4 0 0 0 1 0 0 0 0 1 0 0 0 1 0 0 1 0 0 1 1 0
5 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0 0 1 0 1 0 1
6 0 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0 0 1 0 1 1

4. .
:

n=3

0 1 2
-------0 0 0 0
1 0 0 0
2 0 0 0

-0
1
2


1. ? - .
?
2. .
.
3. ?
?
4. ?
5. . 19.1..

12

?
6. .

.
7. .
4.
.
8. . 19.1..

?
9. ,
. , .
.
10. ,
. .
.

1. .
2.
.
3. .
5. .

1. n<=10
( ).
.
13

) . , .
) . , ,
.
) .
) , ,
.
) .
) 1.
) ( ).
2. n<=10
( ).
) , .
) , .
) .
) , ,
.
3. n<=10 .
) ,
.
) :

v1 > v2,

v1 , v2 .
) ,
.
)

.
4. n<=7,
.
14

k<=28

) .
) .
) , 0.
) , .
) ,
.
) , .

15