Pro.ID21697 TitleChristmas Title链接http://10.20.2.8/oj/exercise/problem?problem_id=21697 AC0 Submit0 Ratio- 时间&空间限制描述Christmas day is coming. There will be a ball in Christmas Eve. N men and N women will take part in the ball. One man and one woman form a pair. As we know, if there is a great difference in age or in height, the pair will be very disappointed. Now we define the disappointment between one man and one woman as: F(i, j)=(Hi - Hj)2 + (AGEi - AGEj)2 Where Hi is the height of person i and AGEi is the age of that person. Your task is to find a plan to form N pairs, with the max disappointment value minimized. 输入Input may contain several test data sets. For each data set, the first line contains an integer N ( 0 < N ≤ 500 ); The first line is followed by 2N lines. The first N lines describe N men, and the last N lines describe N women. Each line contains two integers, the height and the age of a person. You can assume that the height of one person is between 100cm and 200cm and the age is between 10 and 60. Input is ended by N=0, which should not be processed. 输出Description Christmas day is coming. There will be a ball in Christmas Eve. N men and N women will take part in the ball. One man and one woman form a pair. As we know, if there is a great difference in age or in height, the pair will be very disappointed. Now we define the disappointment between one man and one woman as: F(i, j)=(Hi - Hj)2 + (AGEi - AGEj)2 Where Hi is the height of person i and AGEi is the age of that person. Your task is to find a plan to form N pairs, with the max disappointment value minimized. Input Input may contain several test data sets. For each data set, the first line contains an integer N ( 0 < N ≤ 500 ); The first line is followed by 2N lines. The first N lines describe N men, and the last N lines describe N women. Each line contains two integers, the height and the age of a person. You can assume that the height of one person is between 100cm and 200cm and the age is between 10 and 60. Input is ended by N=0, which should not be processed. Output For each data set, print the answer in a single line. Sample Input 2 Sample Output 1801 Source 样例输入2 样例输出1801 作者 |