编程介的小学生 2017-10-15 14:00 采纳率: 20.5%
浏览 1469
已采纳

You Who?

Description

On the first day of first grade at Friendly Elementrary School, it is customary for each student to spend one minute talking to every classmate that he or she does not already know. When student Bob sees an unfamilar face, he says You who?'' A typical response isMe Charlie, you who?'' Then Bob says, ``Me Bob!'' and they talk for a minute. It's very cute. Then, after a minute, they part and each looks for another stranger to greet. This takes time. In class of twenty-nine or thirty mutual strangers, it takes 29 minutes; time that, according to teachers, could be better spent learning the alphabet. Of course, it is rare to have a first grade class where nobody knows anyone else; there are neighbors and playmates who already know each other, so they don't have to go through the get-to-know-you minutes with each other.
The two first grade teachers have requested that, to save time, students be allocated to their two classes so that the difference in the sizes of the classes is at most one, and the time it takes to complete these introductions is as small as possible. There are no more than 60 students in the incoming first grade class.

How can the assignment of students to classes be made? Your job is to write the software that answers the question.

Input

The school records include information about these student friendships, represented as lists of numbers. If there are 29 students, then they are represented by the numbers 1 to 29. The record for a single student includes, first, his/her student identification number (1 to 29, in this example), then the number of his/her acquaintances, then a list of them in no particular order. So, for example, this record
17 4 5 2 14 22

indicates that student 17 knows 4 students: 5, 2, and so on. The records for all the students in the incoming class are represented as the list of numbers that results from concatenating all the student records together. Spaces and line breaks are irrelevent in this format. Thus, this

1 1 2 2 1 1

is a whole database, indicating that there are only two students in the incoming class, and they know each other; and this

1 2 3 4
2 2 3 4
3 2 1 2
4 2 1 2

indicates that 1 doesn't know 2, and 3 doesn't know 4, but all other pairs know each other.

The database has been checked for consistency, so that if A knows B, then B knows A.
Output

Your output should begin with a number that tells how long it will take to complete the introductions in the best possible legal class assignment. For the simple two student problem above, the only legal answer is

0
Sample Input

1 2 3 4
2 2 3 4
3 2 1 2
4 2 1 2
Sample Output

0

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-10-31 04:14
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突