Dormitory distribution problem

xiaoxiao2021-04-08  371

Dormitory

Program file name

: School.cpp / School.Pas / ...

A very famous university

NKU

There are a lot of teaching buildings and dormitory buildings.

The school is thinking about the interests of the students, I hope to have a good distribution plan, so that students will go to the lesson to go to class every morning.

To simplify the problem, we assume

1.

Each teaching building belongs to a college, and there is only one teaching building in each college.

2.

Every morning, each student has a class every morning, and this lesson is a professional class at its college building.

3.

As shown in the figure, the location of the dormitory is

(Pj, qj),

The position of the college building is

(Xi, yi)

When the distance from these two buildings

Dij

The following formula is determined.

Dij = | xi-pi | | yi-qi | 1

The distribution of the dormitory can be very casual, that is, the students of the same college can not live together, and a group of students in a group can live in a dormitory.

Now the school already has a dormitory distribution plan, now entrusting the programming master, you can verify that this scheme is not optimal.

enter

(Please use standard input and output, not to read and write)

Input data

1

Two integers

N, M

.

N (1 <= n <= 100)

For the number of colleges (ie, the number of teaching buildings),

M (1 <= m <= 100)

For the number of dormitory buildings.

Tightly

N

Behavior Every college information, each

3

Integer

:

Location of the college building

Xi, Yi (-1000 <= xi, yi <= 1000)

Number of students

Bi (1 <= bi <= 1000)

.

Below

M

Behavible for each dormitory, every line

3

Integer

:

Dormitory location

PJ, QJ (-1000 <= pj, qj <= 1000)

And the number of students who can live

CJ (1 <= CJ <

=

1000)

.

At last

N

Behavior now has the allocation scheme of the school.

Per line

M

Integer. Each integer

Eij (1 <= i <= n, 1 <= j <= m, 0 <= Eij <= 1000)

Representation

i

How many students living in the college

j

dorm room.

The input scheme must be effective, that is, satisfied

Bi = Ei1 Ei2 ... Eim, CJ> = (E1J E2J ... ENJ)

.

Output

(Please use standard input and output, not to read and write)

If the current solution is the best, as long as the output is output

YES

(Lowercase letters, do not include quotation marks).

Otherwise, before output

"No"

(Small write letters, not including quotation marks), followed by output a superior program, this program is not optimal, but must be better than the original program.

The output format of the program is the same as the format of the input.

N

Row. each line

M

Number. Each integer

Eij (1 <= i <= n, 1 <= j <= m, 0 <= Eij <= 1000)

Representation

i

How many students living in the college

j

dorm room.

Sample input

1

Sample output

1

3 4-3 3 5-2 -2 62 2 5-1 1 31 1 4-2 - 2 70 -1 33 1 1 00 0 6 00 3 0 2

NO3 0 1 10 0 6 00 4 0 1

Sample input

2

Sample output

2

3 4-3 3 5-2 -2 62 2 5-1 1 31 1 4-2 -2 70 -1 33 0 1 10 0 6 00 4 0 1

YES

Have no answer

转载请注明原文地址:https://www.9cbs.com/read-132729.html

New Post(0)