首页 > 试题广场 >

room

[编程题]room

Nowcoder University has 4n students and n dormitories ( Four students per dormitory). Students numbered from 1 to 4n.

And in the first year, the i-th dormitory 's students are (x1[i],x2[i],x3[i],x4[i]), now in the second year, Students need to decide who to live with.

In the second year, you get n tables such as (y1,y2,y3,y4) denote these four students want to live together.

Now you need to decide which dormitory everyone lives in to minimize the number of students who change dormitory.


输入描述:
The first line has one integer n.

Then there are n lines, each line has four integers (x1,x2,x3,x4) denote these four students live together in the first year

Then there are n lines, each line has four integers (y1,y2,y3,y4) denote these four students want to live together in the second year


输出描述:
Output the least number of students need to change dormitory.
示例1

输入

2
1 2 3 4
5 6 7 8
4 6 7 8
1 2 3 5

输出

2

说明

Just swap 4 and 5

备注:
1<=n<=100

1<=x1,x2,x3,x4,y1,y2,y3,y4<=4n

It's guaranteed that no student will live in more than one dormitories.
头像 寒月沉语思不尽
发表于 2023-11-15 18:11:52
题意:给你一个n,代表一共有n个宿舍,每个宿舍4个人。然后给你初始这4n个学生的信息,也就是开始时谁与谁在一个宿舍。然后又给你新的信息,表示搬宿舍后,希望谁跟谁在一个宿舍,问如何安排让哪些学生从旧宿舍搬走,使得搬后在一个宿舍的学生符合新的信息,要求输出最少搬动的人数。 其实我也是看了别人的代码 展开全文