preface

The concept is introduced

  • The basic concepts of the pet adoption problem were described in detail in the previous section what is the Pet adoption problem, so we will not repeat them here.
  • Let’s use concrete examples to illustrate the principle of solving this problem
  • Note: Either all pets or all adopters are in the home at any one time.

The principle of interpretation

  1. On the first day, Little Dom’s pet adoption center opened its doors. Neighbor Wang took his pet Rhubarb to the center. Little Dom was busy cleaning the pet until the night when he used his “magic formula” to knit rhubarb with a characteristic value of 5 and put it around his neck. At this time, there is 1 pet and 0 adopters in the foster home, and the adopters’ dissatisfaction with the pet is 0. The specific effect is shown below.

  1. The next day, neighbor Ruhua sent her pet Xiao Hui to the adoption center, and Xiao Dom was busy cleaning the pet until the night and then used his own “magic formula” to rhubarb on the characteristic value of 9 (note: the pet’s characteristic value is not repeated) to hang on the neck; At this time, there are 2 pets and 0 adopters in the shelter, and the adopters’ dissatisfaction with the pets is 0. The specific effect is shown below.

  1. On the third day, xiao Long, the neighbor, came to the adoption house and said he wanted a pet with a characteristic value of 8. Xiao Domi counted and found that the pet with a characteristic value of 9 was closest to what Xiao Long wanted, so he gave xiao Long the pet ash to adopt. At this time, there is 1 pet and 0 adopters in the foster home, and the satisfaction of adopters to pets is ABS (8-9)=1. The specific effect is shown below.

  1. On the fourth day, the neighbor two dogs came to the adoption, said he wanted a characteristic value of 3 pets, small many meters a calculation, found that the rest of the characteristic value of 5 pets closest to the two dogs want, put the pet rhubarb to two dogs adopted; At this time, there are 0 pets and 0 adopters in the shelter, and the satisfaction of adopters to pets is ABS (8-9)+ ABS (3-5)=3. The specific effect is shown below.

  1. On the fifth day, his neighbor Liansheng came to the foster home and said he wanted a pet with a characteristic value of 10. Little Dom saw that there were no pets in the foster home. At this time, there are 0 pets and 1 adopter in the foster home. The adopter’s dissatisfaction with the pet is ABS (8-9)+ ABS (3-5)=3. The specific effect is shown below.

  1. So, a year later, with a pet and adopter-related trait score, It was easy for Dom to gauge the adopter’s satisfaction with his adoption

Results show

instructions

  • In the public number to reply to the “algorithm source” can get the top ten classic sorting algorithm source
  • Reply “Algorithm books” in the public account to get the classic introduction algorithm books
  • Reply “data structure” in the public number to obtain data structure related source code