首页 > 代码库 > 中兴捧月杯 数字配对

中兴捧月杯 数字配对

一、标题:    数字化婚姻配对尝试二、题目:建立一个模型,来模拟推导社会男女择偶过程。为了模型简化,一个人的特性指标有三个,这里假设为财富、样貌、品格,每个指标均可取值1-100之间任意数字。同样也对这3项指标有自己的需求。这3个需求值取值范围都在1-98间,当然三者的和必须为100.所以任意一个人可以用以下数组来表述:G(A、B、C、A1、B1、C1)G代表男,M代表女。举例G11(80、50、40、10、30、60),表示男11号,拥有财富80、样貌50、品格40,对异性品格的偏好为:财富在乎程度百分之10、样貌在乎程度百分之30、品格在乎程度百分之60。同样为了模型简化,假设信息是完全对称的,即是说,每个人都能一眼就能看清楚任意一个人的财富、样貌、品格。还是为了模型简化,我建模所用样本为男女各100个,即男女人数相同。每个人对异性的满意度将如下定义:每个偏好指标与异性的对应的禀赋指标相乘,三个指标的乘积再相加,即他(她)对某个异性的满意度。举例G11(80、50、40、10、30、60)对M(50、60、80、40、10、50)的满意度为:(10*50+30*60+60*80)= 7100分相对的 MM 对 GG的满意度则为:(40*80+10*50+50*40) = 5700分好了,配对活动开始,设计的配对法则如下:1、100个男方,顺序,轮流从0号到99号女方中挑选自己最满意的一位,然后向她发出配对邀请。2、接受邀请最多的女方开始行动,对这些邀请的男性中,选择最满意的一位。3、那么这两位配对成功,剔除出样本,剩下的99对继续这样配对。4、循环该配对法则,直到最后一对男女配对成功。三、初赛阶段要求:1、编程语言为java,C++或C语言任意一种;运行环境windows。2、能让用户输入自己的参数以及对各项数值的偏好,然后随机生成100位男性100位女性(包括用户在内。如果用为男性则为99男100女),数值全部随机但需满足题设限制。按照上述规则给出一个匹配结果呈现给用户。3、若采用c/c++,要输出可执行程序;若采用java,给出jar和bat。4、在匹配时,如果发现有多个满意度相同的对象,要求自身三个属性(财富,外貌,品格)总和大的优先,如果再相同则id小的优先。如果有2位女士的选票相同,优先级规则同上。请把主角的id置为最小值,以便在前2个条件相同情况下,主角可以优先选择。5、程序读取指定的配置文件,获取样本,然后根据指定的输入,输出结果。同时会给出一组源数据和标准答案给学生自测。最后再让学生根据不同的,指定的输入,给出考试答案。  请点击下载配置文件附件。附件中,male.txt,female.txt,players.txt 分别是男士样本、女士样本和主角样本各 100位。 男女样本中,每行都代表一位男士或女士的基本属性,从左到右依次是ID, 样貌,品格,财富 , 期望样貌,期望品格,期望财富,没有加入性别,需要在解析时手动添加,每个txt文本的性别都是一样的,请注意。另外,主角样本中没有ID属性,换成了性别属性,其中 0表示女性,1表示男性,其余属性依次为样貌,品格,财富,期望样貌 ,期望品格,期望财富。建议把主角的id都设置为 -1,以便满足优先选择的条件。给出标准答案2组,用于考生自测:1号主角(文本第一行),选择的对象属性为(6,18,82,87,3,10)2号主角(文本第二行),选择的对象属性为(27,74,22,22,58,20)同时要求考生输出9号主角(0,72,55,53,8,87,5),19号主角(0,11,4,63,22,60,18),47号主角(1,19,8,21,1,53,46),83号主角(1,23,11,17,58,31,11),99号主角(1,26,66,1,78,11,11)以及100号主角(0,68,28,19,43,11,46)的选择结果
</pre><pre code_snippet_id="402707" snippet_file_name="blog_20140623_1_9081573" name="code" class="java">界面:
</pre><pre name="code" class="java">package jins.start;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.sql.*;


public class DengLu extends JFrame {
<span style="white-space:pre">	</span>
<span style="white-space:pre">	</span>public JLabel name = new JLabel("用户名");
<span style="white-space:pre">	</span>public JLabel pass = new JLabel("密 码");
<span style="white-space:pre">	</span>public JTextField userName = new JTextField();
<span style="white-space:pre">	</span>public JPasswordField passWord = new JPasswordField();
<span style="white-space:pre">	</span>public Button bok = new Button("登陆");
<span style="white-space:pre">	</span>public Button bexit = new Button("取消");


<span style="white-space:pre">	</span>public DengLu() {
<span style="white-space:pre">		</span>this.setContentPane(new MyPanel());


<span style="white-space:pre">		</span>setTitle("欢迎使用数字配对系统");
<span style="white-space:pre">		</span>setLayout(null);
<span style="white-space:pre">		</span>setSize(500, 400);
<span style="white-space:pre">		</span>setResizable(false);
<span style="white-space:pre">		</span>setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


<span style="white-space:pre">		</span>Dimension scr = Toolkit.getDefaultToolkit().getScreenSize();
<span style="white-space:pre">		</span>Dimension frm = this.getSize();
<span style="white-space:pre">		</span>setLocation( (scr.width - frm.width) / 2,
<span style="white-space:pre">				</span>(scr.height - frm.height) / 2 - 18);


<span style="white-space:pre">		</span>name.setBounds(70, 260, 120, 20);
<span style="white-space:pre">		</span>userName.setBounds(120, 260, 120, 27);
<span style="white-space:pre">		</span>pass.setBounds(70, 300, 120, 20);
<span style="white-space:pre">		</span>passWord.setBounds(120, 300, 120, 27);
<span style="white-space:pre">		</span>passWord.setEchoChar('*');
<span style="white-space:pre">		</span>bok.setBounds(340, 260, 100, 28);
<span style="white-space:pre">		</span>bexit.setBounds(340, 300, 100, 28);


<span style="white-space:pre">		</span>add(name);
<span style="white-space:pre">		</span>add(userName);
<span style="white-space:pre">		</span>add(pass);
<span style="white-space:pre">		</span>add(passWord);
<span style="white-space:pre">		</span>add(bok);
<span style="white-space:pre">		</span>add(bexit);
<span style="white-space:pre">		</span>setVisible(true);


<span style="white-space:pre">		</span>bexit.addActionListener(new ActionListener() {
<span style="white-space:pre">			</span>public void actionPerformed(ActionEvent e) {



<span style="white-space:pre">				</span>System.exit(0);
<span style="white-space:pre">			</span>}
<span style="white-space:pre">		</span>});
<span style="white-space:pre">		</span>bok.addActionListener(new ActionListener() {
<span style="white-space:pre">			</span>public void actionPerformed(ActionEvent e) {
<span style="white-space:pre">				</span>if (userName.getText().equals("")) {
<span style="white-space:pre">					</span>JOptionPane.showMessageDialog(null, "用户名不能为空!");
<span style="white-space:pre">				</span>} else if (passWord.getText().equals("")) {
<span style="white-space:pre">					</span>JOptionPane.showMessageDialog(null, "密码不能为空!");
<span style="white-space:pre">				</span>} else {
<span style="white-space:pre">					</span>if (userName.getText().equals("admin") &&
<span style="white-space:pre">							</span>passWord.getText().equals("admin")) {
<span style="white-space:pre">						</span>dispose();
<span style="white-space:pre">						</span>Activity activity = new Activity();
<span style="white-space:pre">						</span>activity.init();
<span style="white-space:pre">						</span>Frame frame = new Frame(activity);
<span style="white-space:pre">						</span>frame.show();


<span style="white-space:pre">					</span>} else {
<span style="white-space:pre">						</span>JOptionPane.showMessageDialog(null, "密码错误");
<span style="white-space:pre">						</span>userName.setText(null);
<span style="white-space:pre">						</span>passWord.setText(null);
<span style="white-space:pre">					</span>}
<span style="white-space:pre">				</span>}
<span style="white-space:pre">			</span>}
<span style="white-space:pre">		</span>});
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>


<span style="white-space:pre">	</span>private class MyPanel extends JPanel {
<span style="white-space:pre">		</span>public void paintComponent(Graphics g) {
<span style="white-space:pre">			</span>Graphics2D g2 = (Graphics2D)g;
<span style="white-space:pre">			</span>super.paintComponent(g);
<span style="white-space:pre">			</span>Image img = Toolkit.getDefaultToolkit().getImage("bg.jpg");
<span style="white-space:pre">			</span>g2.drawImage(img, 0, 0, this.getWidth(), this.getHeight(), this);
<span style="white-space:pre">		</span>}
<span style="white-space:pre">	</span>}
}


package jins.start;


import jins.start.Activity;
import jins.start.Person;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.NumberFormat;
import javax.swing.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.sql.*;




public class Frame  
{


<span style="white-space:pre">	</span>private JFrame frame;
<span style="white-space:pre">	</span>private JTextArea infoArea;
<span style="white-space:pre">	</span>private Activity activity;
<span style="white-space:pre">	</span>
<span style="white-space:pre">	</span>
<span style="white-space:pre">	</span>public Frame(Activity activity)
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>this.activity = activity;
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>public void show()
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>
<span style="white-space:pre">		</span>
<span style="white-space:pre">		</span>
<span style="white-space:pre">		</span>
<span style="white-space:pre">		</span>frame = new JFrame();
<span style="white-space:pre">		</span>frame.setTitle("数字化配对");
<span style="white-space:pre">		</span>frame.setDefaultCloseOperation(3);
<span style="white-space:pre">		</span>int width = Toolkit.getDefaultToolkit().getScreenSize().width;
<span style="white-space:pre">		</span>int height = Toolkit.getDefaultToolkit().getScreenSize().height;
<span style="white-space:pre">		</span>frame.setLocation(width / 2 - 200, height / 2 - 150);
<span style="white-space:pre">		</span>init();
<span style="white-space:pre">		</span>frame.pack();
<span style="white-space:pre">		</span>frame.setVisible(true);
<span style="white-space:pre">		</span>frame.setResizable(false);
<span style="white-space:pre">		</span>frame.setSize(800, 400);
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>private void init()
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>InputVerifier verifier = new InputVerifier() {


<span style="white-space:pre">			</span>final Frame this$0;


<span style="white-space:pre">			</span>
<span style="white-space:pre">			</span>
<span style="white-space:pre">			</span>public boolean verify(JComponent input)
<span style="white-space:pre">			</span>{
<span style="white-space:pre">				</span>JFormattedTextField field = (JFormattedTextField)input;
<span style="white-space:pre">				</span>if (field.isEditValid())
<span style="white-space:pre">				</span>{
<span style="white-space:pre">					</span>if (field.getText() == null || field.getText().trim().equals(""))
<span style="white-space:pre">					</span>{
<span style="white-space:pre">						</span>infoArea.append((new StringBuilder(String.valueOf(field.getName()))).append("输入错误,请输入1~98数字 \n").toString());
<span style="white-space:pre">						</span>return false;
<span style="white-space:pre">					</span>}
<span style="white-space:pre">					</span>int value = http://www.mamicode.com/Integer.parseInt(field.getText());>
</pre><pre code_snippet_id="402707" snippet_file_name="blog_20140623_1_9081573" name="code" class="java">载入文件:
package jins.start;


import jins.start.Person;
import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;


public class Loader
{


<span style="white-space:pre">	</span>public Loader()
<span style="white-space:pre">	</span>{
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>public static ArrayList loadPlayerList(String path)
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>ArrayList list;
<span style="white-space:pre">		</span>BufferedReader reader;
<span style="white-space:pre">		</span>list = new ArrayList();
<span style="white-space:pre">		</span>reader = null;
<span style="white-space:pre">		</span>try {
<span style="white-space:pre">			</span>reader = new BufferedReader(new FileReader(path));
<span style="white-space:pre">		</span>} catch (FileNotFoundException e) {
<span style="white-space:pre">			</span>// TODO Auto-generated catch block
<span style="white-space:pre">			</span>e.printStackTrace();
<span style="white-space:pre">		</span>}
<span style="white-space:pre">		</span>try {
<span style="white-space:pre">			</span>for (String line = ""; (line = reader.readLine()) != null;)
<span style="white-space:pre">			</span>{
<span style="white-space:pre">				</span>String array[] = line.split(",");
<span style="white-space:pre">				</span>list.add(new Person(-1, Integer.parseInt(array[0]), Integer.parseInt(array[1]), Integer.parseInt(array[2]), Integer.parseInt(array[3]), Integer.parseInt(array[4]), Integer.parseInt(array[5]), Integer.parseInt(array[6])));
<span style="white-space:pre">			</span>}
<span style="white-space:pre">		</span>} catch (NumberFormatException e) {
<span style="white-space:pre">			</span>// TODO Auto-generated catch block
<span style="white-space:pre">			</span>e.printStackTrace();
<span style="white-space:pre">		</span>} catch (IOException e) {
<span style="white-space:pre">			</span>// TODO Auto-generated catch block
<span style="white-space:pre">			</span>e.printStackTrace();
<span style="white-space:pre">		</span>}


<span style="white-space:pre">		</span>
<span style="white-space:pre">		</span>
<span style="white-space:pre">		</span>
<span style="white-space:pre">		</span>
<span style="white-space:pre">	</span>
<span style="white-space:pre">		</span>if (reader != null)
<span style="white-space:pre">		</span>{
<span style="white-space:pre">			</span>try
<span style="white-space:pre">			</span>{
<span style="white-space:pre">				</span>reader.close();
<span style="white-space:pre">			</span>}
<span style="white-space:pre">			</span>catch (IOException e1)
<span style="white-space:pre">			</span>{
<span style="white-space:pre">				</span>e1.printStackTrace();
<span style="white-space:pre">			</span>}
<span style="white-space:pre">			</span>reader = null;
<span style="white-space:pre">		</span>}
<span style="white-space:pre">		</span>
<span style="white-space:pre">		</span>//e;
<span style="white-space:pre">		</span>
<span style="white-space:pre">	</span>
<span style="white-space:pre">		</span>
<span style="white-space:pre">		</span>
<span style="white-space:pre">		</span>return list;
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>public static HashMap loadSampleMap(String path, int gender)
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>HashMap map;
<span style="white-space:pre">		</span>BufferedReader reader;
<span style="white-space:pre">		</span>map = new HashMap();
<span style="white-space:pre">		</span>reader = null;
<span style="white-space:pre">		</span>try {
<span style="white-space:pre">			</span>reader = new BufferedReader(new FileReader(path));
<span style="white-space:pre">		</span>} catch (FileNotFoundException e) {
<span style="white-space:pre">			</span>// TODO Auto-generated catch block
<span style="white-space:pre">			</span>e.printStackTrace();
<span style="white-space:pre">		</span>}
<span style="white-space:pre">		</span>try {
<span style="white-space:pre">			</span>for (String line = ""; (line = reader.readLine()) != null;)
<span style="white-space:pre">			</span>{
<span style="white-space:pre">				</span>String array[] = line.split(",");
<span style="white-space:pre">				</span>int id = Integer.parseInt(array[0]);
<span style="white-space:pre">				</span>map.put(Integer.valueOf(id), new Person(id, gender, Integer.parseInt(array[1]), Integer.parseInt(array[2]), Integer.parseInt(array[3]), Integer.parseInt(array[4]), Integer.parseInt(array[5]), Integer.parseInt(array[6])));
<span style="white-space:pre">			</span>}
<span style="white-space:pre">		</span>} catch (NumberFormatException e) {
<span style="white-space:pre">			</span>// TODO Auto-generated catch block
<span style="white-space:pre">			</span>e.printStackTrace();
<span style="white-space:pre">		</span>} catch (IOException e) {
<span style="white-space:pre">			</span>// TODO Auto-generated catch block
<span style="white-space:pre">			</span>e.printStackTrace();
<span style="white-space:pre">		</span>}


<span style="white-space:pre">		</span>try {
<span style="white-space:pre">			</span>reader.close();
<span style="white-space:pre">		</span>} catch (IOException e) {
<span style="white-space:pre">			</span>// TODO Auto-generated catch block
<span style="white-space:pre">			</span>e.printStackTrace();
<span style="white-space:pre">		</span>}
<span style="white-space:pre">	</span>
<span style="white-space:pre">	</span>
<span style="white-space:pre">		</span>
<span style="white-space:pre">		</span>
<span style="white-space:pre">	</span>


<span style="white-space:pre">		</span>
<span style="white-space:pre">		</span>return map;
<span style="white-space:pre">	</span>}
}
模拟投票:
package jins.start;


import java.util.ArrayList;


//Referenced classes of package cn.gucas.dsp.pengf.mg.model:
//<span style="white-space:pre">			</span>Person


public class Vote
{


<span style="white-space:pre">	</span>private int id;
<span style="white-space:pre">	</span>private ArrayList voters;


<span style="white-space:pre">	</span>public Vote()
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>voters = new ArrayList();
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>public void addVoter(Person person)
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>voters.add(person);
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>public int getId()
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>return id;
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>public void setId(int id)
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>this.id = id;
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>public ArrayList getVoters()
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>return voters;
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>public void setVoters(ArrayList voters)
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>this.voters = voters;
<span style="white-space:pre">	</span>}
}
条件筛选:
package jins.start;


public class Satisfaction implements Comparable
{


<span style="white-space:pre">	</span>private Person person;
<span style="white-space:pre">	</span>private int satisfaction;


<span style="white-space:pre">	</span>public Satisfaction()
<span style="white-space:pre">	</span>{
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>public Person getPerson()
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>return person;
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>public void setPerson(Person person)
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>this.person = person;
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>public int getSatisfaction()
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>return satisfaction;
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>public void setSatisfaction(int satisfaction)
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>this.satisfaction = satisfaction;
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>public int compareTo(Satisfaction other)
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>if (satisfaction > other.satisfaction)
<span style="white-space:pre">			</span>return -1;
<span style="white-space:pre">		</span>if (satisfaction < other.satisfaction)
<span style="white-space:pre">			</span>return 1;
<span style="white-space:pre">		</span>if (person.getTotalQuality() > other.person.getTotalQuality())
<span style="white-space:pre">			</span>return -1;
<span style="white-space:pre">		</span>if (person.getTotalQuality() < other.person.getTotalQuality())
<span style="white-space:pre">			</span>return 1;
<span style="white-space:pre">		</span>return person.getId() >= other.person.getId() ? 1 : -1;
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>public int compareTo(Object obj)
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>return compareTo((Satisfaction)obj);
<span style="white-space:pre">	</span>}
}
任务属性:
package jins.start;


import java.util.Iterator;
import java.util.PriorityQueue;


// Referenced classes of package cn.gucas.dsp.pengf.mg.model:
//<span style="white-space:pre">			</span>Satisfaction


public class Person
{


<span style="white-space:pre">	</span>private int id;
<span style="white-space:pre">	</span>private int gender;
<span style="white-space:pre">	</span>private int fortune;
<span style="white-space:pre">	</span>private int appearance;
<span style="white-space:pre">	</span>private int character;
<span style="white-space:pre">	</span>private int requireFortune;
<span style="white-space:pre">	</span>private int requireAppearance;
<span style="white-space:pre">	</span>private int requireCharacter;
<span style="white-space:pre">	</span>private PriorityQueue satisfactionQueue;
<span style="white-space:pre">	</span>private PriorityQueue backupSatisfactionQueue;


<span style="white-space:pre">	</span>public Person(int id, int gender, int fortune, int appearance, int character, int requireFortune, int requireAppearance, 
<span style="white-space:pre">			</span>int requireCharacter)
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>satisfactionQueue = new PriorityQueue();
<span style="white-space:pre">		</span>backupSatisfactionQueue = new PriorityQueue();
<span style="white-space:pre">		</span>this.id = id;
<span style="white-space:pre">		</span>this.gender = gender;
<span style="white-space:pre">		</span>this.fortune = fortune;
<span style="white-space:pre">		</span>this.appearance = appearance;
<span style="white-space:pre">		</span>this.character = character;
<span style="white-space:pre">		</span>this.requireFortune = requireFortune;
<span style="white-space:pre">		</span>this.requireAppearance = requireAppearance;
<span style="white-space:pre">		</span>this.requireCharacter = requireCharacter;
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>private int getSatisfaction(Person person)
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>return requireFortune * person.fortune + requireAppearance * person.appearance + requireCharacter * person.character;
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>public void judgePerson(Person person)
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>Satisfaction satisfaction = new Satisfaction();
<span style="white-space:pre">		</span>satisfaction.setPerson(person);
<span style="white-space:pre">		</span>satisfaction.setSatisfaction(getSatisfaction(person));
<span style="white-space:pre">		</span>satisfactionQueue.add(satisfaction);
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>public void buildBackupPriorityQueue()
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>backupSatisfactionQueue.clear();
<span style="white-space:pre">		</span>Satisfaction satisfaction;
<span style="white-space:pre">		</span>for (Iterator iterator = satisfactionQueue.iterator(); iterator.hasNext(); backupSatisfactionQueue.add(satisfaction))
<span style="white-space:pre">			</span>satisfaction = (Satisfaction)iterator.next();


<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>public void changePlayer(Person person)
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>buildBackupPriorityQueue();
<span style="white-space:pre">		</span>Satisfaction satisfaction = new Satisfaction();
<span style="white-space:pre">		</span>satisfaction.setPerson(person);
<span style="white-space:pre">		</span>satisfaction.setSatisfaction(getSatisfaction(person));
<span style="white-space:pre">		</span>backupSatisfactionQueue.add(satisfaction);
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>public int getTotalQuality()
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>return fortune + appearance + character;
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>public int peekGod()
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>return ((Satisfaction)backupSatisfactionQueue.peek()).getPerson().getId();
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>public int pollGod()
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>return ((Satisfaction)backupSatisfactionQueue.poll()).getPerson().getId();
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>public int getId()
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>return id;
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>public void setId(int id)
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>this.id = id;
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>public int getGender()
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>return gender;
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>public void setGender(int gender)
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>this.gender = gender;
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>public int getFortune()
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>return fortune;
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>public void setFortune(int fortune)
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>this.fortune = fortune;
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>public int getAppearance()
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>return appearance;
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>public void setAppearance(int appearance)
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>this.appearance = appearance;
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>public int getCharacter()
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>return character;
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>public void setCharacter(int character)
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>this.character = character;
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>public int getRequireFortune()
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>return requireFortune;
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>public void setRequireFortune(int requireFortune)
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>this.requireFortune = requireFortune;
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>public int getRequireAppearance()
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>return requireAppearance;
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>public void setRequireAppearance(int requireAppearance)
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>this.requireAppearance = requireAppearance;
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>public int getRequireCharacter()
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>return requireCharacter;
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>public void setRequireCharacter(int requireCharacter)
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>this.requireCharacter = requireCharacter;
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>public String toString()
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>return (new StringBuilder("[")).append(id).append(":").append(fortune).append(",").append(appearance).append(",").append(character).append(",").append(requireFortune).append(",").append(requireAppearance).append(",").append(requireCharacter).append("]").toString();
<span style="white-space:pre">	</span>}
}
必要的常量:
package jins.start;


public class Constants
{


<span style="white-space:pre">	</span>public static final String FEMALE_SAMPLE_PATH = "./conf/female.txt";
<span style="white-space:pre">	</span>public static final String MALE_SAMPLE_PATH = "./conf/male.txt";
<span style="white-space:pre">	</span>public static final String PLAYERS_PATH = "./conf/players.txt";
<span style="white-space:pre">	</span>public static final int FEMALE = 0;
<span style="white-space:pre">	</span>public static final int MALE = 1;
<span style="white-space:pre">	</span>public static final int PLAYER_ID = -1;
<span style="white-space:pre">	</span>public static final int N = 100;


<span style="white-space:pre">	</span>public Constants()
<span style="white-space:pre">	</span>{
<span style="white-space:pre">	</span>}
}
下面就是逻辑类了:


package jins.start;


import jins.start.Person;
import jins.start.Vote;
import jins.start.Loader;
import java.util.*;


public class Activity
{


<span style="white-space:pre">	</span>private HashMap femaleMap;
<span style="white-space:pre">	</span>private HashMap maleMap;
<span style="white-space:pre">	</span>private ArrayList playerList;
<span style="white-space:pre">	</span>private HashMap randomFemaleMap;
<span style="white-space:pre">	</span>private HashMap randomMaleMap;


<span style="white-space:pre">	</span>public Activity()
<span style="white-space:pre">	</span>{
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>public void init()
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>femaleMap = Loader.loadSampleMap("./conf/female.txt", 0);
<span style="white-space:pre">		</span>maleMap = Loader.loadSampleMap("./conf/male.txt", 1);
<span style="white-space:pre">		</span>playerList = Loader.loadPlayerList("./conf/players.txt");
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>public String generate(int gender)
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>randomFemaleMap = new HashMap();
<span style="white-space:pre">		</span>randomMaleMap = new HashMap();
<span style="white-space:pre">		</span>StringBuilder sb = new StringBuilder();
<span style="white-space:pre">		</span>sb.append("男生                           \t女生 \n");
<span style="white-space:pre">		</span>for (int i = 0; i < 99; i++)
<span style="white-space:pre">		</span>{
<span style="white-space:pre">			</span>int fortune = (int)(Math.random() * 98D + 1.0D);
<span style="white-space:pre">			</span>int appearance = (int)(Math.random() * 98D + 1.0D);
<span style="white-space:pre">			</span>int charactor = (int)(Math.random() * 98D + 1.0D);
<span style="white-space:pre">			</span>int requireFortune = (int)(Math.random() * 98D + 1.0D);
<span style="white-space:pre">			</span>int requireAppearance = (int)(Math.random() * 98D + 1.0D);
<span style="white-space:pre">			</span>int requireCharactor = 100 - requireFortune - requireAppearance;
<span style="white-space:pre">			</span>Person male = new Person(i + 1, 1, fortune, appearance, charactor, requireFortune, requireAppearance, requireCharactor);
<span style="white-space:pre">			</span>randomMaleMap.put(Integer.valueOf(i + 1), male);
<span style="white-space:pre">			</span>sb.append((new StringBuilder()).append(male).append("\t").toString());
<span style="white-space:pre">			</span>fortune = (int)(Math.random() * 98D + 1.0D);
<span style="white-space:pre">			</span>appearance = (int)(Math.random() * 98D + 1.0D);
<span style="white-space:pre">			</span>charactor = (int)(Math.random() * 98D + 1.0D);
<span style="white-space:pre">			</span>requireFortune = (int)(Math.random() * 98D + 1.0D);
<span style="white-space:pre">			</span>requireAppearance = (int)(Math.random() * 98D + 1.0D);
<span style="white-space:pre">			</span>requireCharactor = 100 - requireFortune - requireAppearance;
<span style="white-space:pre">			</span>Person female = new Person(i + 1, 0, fortune, appearance, charactor, requireFortune, requireAppearance, requireCharactor);
<span style="white-space:pre">			</span>randomFemaleMap.put(Integer.valueOf(i + 1), female);
<span style="white-space:pre">			</span>sb.append((new StringBuilder()).append(female).append("\n").toString());
<span style="white-space:pre">		</span>}


<span style="white-space:pre">		</span>if (gender == 1)
<span style="white-space:pre">		</span>{
<span style="white-space:pre">			</span>int fortune = (int)(Math.random() * 98D + 1.0D);
<span style="white-space:pre">			</span>int appearance = (int)(Math.random() * 98D + 1.0D);
<span style="white-space:pre">			</span>int charactor = (int)(Math.random() * 98D + 1.0D);
<span style="white-space:pre">			</span>int requireFortune = (int)(Math.random() * 98D + 1.0D);
<span style="white-space:pre">			</span>int requireAppearance = (int)(Math.random() * 98D + 1.0D);
<span style="white-space:pre">			</span>int requireCharactor = 100 - requireFortune - requireAppearance;
<span style="white-space:pre">			</span>Person female = new Person(100, 0, fortune, appearance, charactor, requireFortune, requireAppearance, requireCharactor);
<span style="white-space:pre">			</span>randomFemaleMap.put(Integer.valueOf(100), female);
<span style="white-space:pre">			</span>sb.append((new StringBuilder("              \t       \t")).append(female).append("\n").toString());
<span style="white-space:pre">		</span>} else
<span style="white-space:pre">		</span>{
<span style="white-space:pre">			</span>int fortune = (int)(Math.random() * 98D + 1.0D);
<span style="white-space:pre">			</span>int appearance = (int)(Math.random() * 98D + 1.0D);
<span style="white-space:pre">			</span>int charactor = (int)(Math.random() * 98D + 1.0D);
<span style="white-space:pre">			</span>int requireFortune = (int)(Math.random() * 98D + 1.0D);
<span style="white-space:pre">			</span>int requireAppearance = (int)(Math.random() * 98D + 1.0D);
<span style="white-space:pre">			</span>int requireCharactor = 100 - requireFortune - requireAppearance;
<span style="white-space:pre">			</span>Person male = new Person(100, 1, fortune, appearance, charactor, requireFortune, requireAppearance, requireCharactor);
<span style="white-space:pre">			</span>randomMaleMap.put(Integer.valueOf(100), male);
<span style="white-space:pre">			</span>sb.append((new StringBuilder()).append(male).append("\n").toString());
<span style="white-space:pre">		</span>}
<span style="white-space:pre">		</span>return sb.toString();
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>public String join(Person player)
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>StringBuilder sb = new StringBuilder();
<span style="white-space:pre">		</span>for (Iterator iterator = randomMaleMap.keySet().iterator(); iterator.hasNext();)
<span style="white-space:pre">		</span>{
<span style="white-space:pre">			</span>Integer maleId = (Integer)iterator.next();
<span style="white-space:pre">			</span>Person male = (Person)randomMaleMap.get(maleId);
<span style="white-space:pre">			</span>Person female;
<span style="white-space:pre">			</span>for (Iterator iterator5 = randomFemaleMap.keySet().iterator(); iterator5.hasNext(); female.judgePerson(male))
<span style="white-space:pre">			</span>{
<span style="white-space:pre">				</span>Integer femaleId = (Integer)iterator5.next();
<span style="white-space:pre">				</span>female = (Person)randomFemaleMap.get(femaleId);
<span style="white-space:pre">				</span>male.judgePerson(female);
<span style="white-space:pre">			</span>}


<span style="white-space:pre">		</span>}


<span style="white-space:pre">		</span>HashSet maleGodSet;
<span style="white-space:pre">		</span>HashSet femaleGodSet;
<span style="white-space:pre">		</span>HashMap votes;
<span style="white-space:pre">		</span>if (player.getGender() == 1)
<span style="white-space:pre">		</span>{
<span style="white-space:pre">			</span>randomMaleMap.put(Integer.valueOf(player.getId()), player);
<span style="white-space:pre">			</span>maleGodSet = new HashSet();
<span style="white-space:pre">			</span>femaleGodSet = new HashSet();
<span style="white-space:pre">			</span>Person female;
<span style="white-space:pre">			</span>for (Iterator iterator1 = randomFemaleMap.keySet().iterator(); iterator1.hasNext(); female.changePlayer(player))
<span style="white-space:pre">			</span>{
<span style="white-space:pre">				</span>Integer femaleId = (Integer)iterator1.next();
<span style="white-space:pre">				</span>female = (Person)randomFemaleMap.get(femaleId);
<span style="white-space:pre">				</span>player.judgePerson(female);
<span style="white-space:pre">			</span>}


<span style="white-space:pre">			</span>Person male;
<span style="white-space:pre">			</span>for (Iterator iterator2 = randomMaleMap.keySet().iterator(); iterator2.hasNext(); male.buildBackupPriorityQueue())
<span style="white-space:pre">			</span>{
<span style="white-space:pre">				</span>Integer maleId = (Integer)iterator2.next();
<span style="white-space:pre">				</span>male = (Person)randomMaleMap.get(maleId);
<span style="white-space:pre">			</span>}


<span style="white-space:pre">			</span>votes = new HashMap();
<span style="white-space:pre">			</span>for (Iterator iterator6 = randomMaleMap.keySet().iterator(); iterator6.hasNext();)
<span style="white-space:pre">			</span>{
<span style="white-space:pre">				</span>Integer maleId = (Integer)iterator6.next();
<span style="white-space:pre">				</span>Person male1 = (Person)randomMaleMap.get(maleId);
<span style="white-space:pre">				</span>int femaleGodId = male1.peekGod();
<span style="white-space:pre">				</span>if (votes.containsKey(Integer.valueOf(femaleGodId)))
<span style="white-space:pre">				</span>{
<span style="white-space:pre">					</span>Vote vote = (Vote)votes.get(Integer.valueOf(femaleGodId));
<span style="white-space:pre">					</span>vote.addVoter(male1);
<span style="white-space:pre">				</span>} else
<span style="white-space:pre">				</span>{
<span style="white-space:pre">					</span>Vote vote = new Vote();
<span style="white-space:pre">					</span>vote.setId(femaleGodId);
<span style="white-space:pre">					</span>vote.addVoter(male1);
<span style="white-space:pre">					</span>votes.put(Integer.valueOf(femaleGodId), vote);
<span style="white-space:pre">				</span>}
<span style="white-space:pre">			</span>}


<span style="white-space:pre">			</span>do
<span style="white-space:pre">			</span>{
<span style="white-space:pre">				</span>int maxVote = 0x80000000;
<span style="white-space:pre">				</span>int femaleGodId = 0x80000000;
<span style="white-space:pre">				</span>for (Iterator iterator8 = votes.keySet().iterator(); iterator8.hasNext();)
<span style="white-space:pre">				</span>{
<span style="white-space:pre">					</span>Integer key = (Integer)iterator8.next();
<span style="white-space:pre">					</span>int voteNum = ((Vote)votes.get(key)).getVoters().size();
<span style="white-space:pre">					</span>if (voteNum > maxVote)
<span style="white-space:pre">					</span>{
<span style="white-space:pre">						</span>maxVote = voteNum;
<span style="white-space:pre">						</span>femaleGodId = key.intValue();
<span style="white-space:pre">					</span>} else
<span style="white-space:pre">					</span>if (voteNum == maxVote)
<span style="white-space:pre">					</span>{
<span style="white-space:pre">						</span>int competitorQuality = ((Person)randomFemaleMap.get(key)).getTotalQuality();
<span style="white-space:pre">						</span>int femaleGodQuality = ((Person)randomFemaleMap.get(Integer.valueOf(femaleGodId))).getTotalQuality();
<span style="white-space:pre">						</span>if (competitorQuality > femaleGodQuality)
<span style="white-space:pre">						</span>{
<span style="white-space:pre">							</span>maxVote = voteNum;
<span style="white-space:pre">							</span>femaleGodId = key.intValue();
<span style="white-space:pre">						</span>} else
<span style="white-space:pre">						</span>if (competitorQuality == femaleGodQuality && key.intValue() < femaleGodId)
<span style="white-space:pre">						</span>{
<span style="white-space:pre">							</span>maxVote = voteNum;
<span style="white-space:pre">							</span>femaleGodId = key.intValue();
<span style="white-space:pre">						</span>}
<span style="white-space:pre">					</span>}
<span style="white-space:pre">				</span>}


<span style="white-space:pre">				</span>femaleGodSet.add(Integer.valueOf(femaleGodId));
<span style="white-space:pre">				</span>Person femaleGod = (Person)randomFemaleMap.get(Integer.valueOf(femaleGodId));
<span style="white-space:pre">				</span>int maleGodId;
<span style="white-space:pre">				</span>for (maleGodId = femaleGod.pollGod(); maleGodSet.contains(Integer.valueOf(maleGodId)) || ((Person)randomMaleMap.get(Integer.valueOf(maleGodId))).peekGod() != femaleGodId; maleGodId = femaleGod.pollGod());
<span style="white-space:pre">				</span>maleGodSet.add(Integer.valueOf(maleGodId));
<span style="white-space:pre">				</span>if (maleGodId == -1)
<span style="white-space:pre">				</span>{
<span style="white-space:pre">					</span>sb.append((new StringBuilder()).append(randomMaleMap.get(Integer.valueOf(maleGodId))).append(" <--> ").append(randomFemaleMap.get(Integer.valueOf(femaleGodId))).append("\n").toString());
<span style="white-space:pre">					</span>return sb.toString();
<span style="white-space:pre">				</span>}
<span style="white-space:pre">				</span>ArrayList voters = ((Vote)votes.get(Integer.valueOf(femaleGodId))).getVoters();
<span style="white-space:pre">				</span>for (Iterator iterator10 = voters.iterator(); iterator10.hasNext();)
<span style="white-space:pre">				</span>{
<span style="white-space:pre">					</span>Person voter = (Person)iterator10.next();
<span style="white-space:pre">					</span>if (voter.getId() != maleGodId)
<span style="white-space:pre">					</span>{
<span style="white-space:pre">						</span>voter.pollGod();
<span style="white-space:pre">						</span>int nextGodId;
<span style="white-space:pre">						</span>for (nextGodId = voter.peekGod(); femaleGodSet.contains(Integer.valueOf(nextGodId)); nextGodId = voter.peekGod())
<span style="white-space:pre">							</span>voter.pollGod();


<span style="white-space:pre">						</span>if (votes.containsKey(Integer.valueOf(nextGodId)))
<span style="white-space:pre">						</span>{
<span style="white-space:pre">							</span>Vote vote = (Vote)votes.get(Integer.valueOf(nextGodId));
<span style="white-space:pre">							</span>vote.addVoter(voter);
<span style="white-space:pre">						</span>} else
<span style="white-space:pre">						</span>{
<span style="white-space:pre">							</span>Vote vote = new Vote();
<span style="white-space:pre">							</span>vote.setId(nextGodId);
<span style="white-space:pre">							</span>vote.addVoter(voter);
<span style="white-space:pre">							</span>votes.put(Integer.valueOf(nextGodId), vote);
<span style="white-space:pre">						</span>}
<span style="white-space:pre">					</span>}
<span style="white-space:pre">				</span>}


<span style="white-space:pre">				</span>votes.remove(Integer.valueOf(femaleGodId));
<span style="white-space:pre">			</span>} while (true);
<span style="white-space:pre">		</span>}
<span style="white-space:pre">		</span>randomFemaleMap.put(Integer.valueOf(player.getId()), player);
<span style="white-space:pre">		</span>maleGodSet = new HashSet();
<span style="white-space:pre">		</span>femaleGodSet = new HashSet();
<span style="white-space:pre">		</span>Person male;
<span style="white-space:pre">		</span>for (Iterator iterator3 = randomMaleMap.keySet().iterator(); iterator3.hasNext(); male.changePlayer(player))
<span style="white-space:pre">		</span>{
<span style="white-space:pre">			</span>Integer maleId = (Integer)iterator3.next();
<span style="white-space:pre">			</span>male = (Person)randomMaleMap.get(maleId);
<span style="white-space:pre">			</span>player.judgePerson(male);
<span style="white-space:pre">		</span>}


<span style="white-space:pre">		</span>Person female;
<span style="white-space:pre">		</span>for (Iterator iterator4 = randomFemaleMap.keySet().iterator(); iterator4.hasNext(); female.buildBackupPriorityQueue())
<span style="white-space:pre">		</span>{
<span style="white-space:pre">			</span>Integer femaleId = (Integer)iterator4.next();
<span style="white-space:pre">			</span>female = (Person)randomFemaleMap.get(femaleId);
<span style="white-space:pre">		</span>}


<span style="white-space:pre">		</span>HashMap femaleId = new HashMap();
<span style="white-space:pre">		</span>for (Iterator iterator7 = randomMaleMap.keySet().iterator(); iterator7.hasNext();)
<span style="white-space:pre">		</span>{
<span style="white-space:pre">			</span>Integer maleId = (Integer)iterator7.next();
<span style="white-space:pre">			</span>Person male1 = (Person)randomMaleMap.get(maleId);
<span style="white-space:pre">			</span>int femaleGodId = male1.peekGod();
<span style="white-space:pre">			</span>if (femaleId.containsKey(Integer.valueOf(femaleGodId)))
<span style="white-space:pre">			</span>{
<span style="white-space:pre">				</span>Vote vote = (Vote)femaleId.get(Integer.valueOf(femaleGodId));
<span style="white-space:pre">				</span>vote.addVoter(male1);
<span style="white-space:pre">			</span>} else
<span style="white-space:pre">			</span>{
<span style="white-space:pre">				</span>Vote vote = new Vote();
<span style="white-space:pre">				</span>vote.setId(femaleGodId);
<span style="white-space:pre">				</span>vote.addVoter(male1);
<span style="white-space:pre">				</span>femaleId.put(Integer.valueOf(femaleGodId), vote);
<span style="white-space:pre">			</span>}
<span style="white-space:pre">		</span>}


<span style="white-space:pre">		</span>do
<span style="white-space:pre">		</span>{
<span style="white-space:pre">			</span>int maxVote = 0x80000000;
<span style="white-space:pre">			</span>int femaleGodId = 0x80000000;
<span style="white-space:pre">			</span>for (Iterator iterator9 = femaleId.keySet().iterator(); iterator9.hasNext();)
<span style="white-space:pre">			</span>{
<span style="white-space:pre">				</span>Integer key = (Integer)iterator9.next();
<span style="white-space:pre">				</span>int voteNum = ((Vote)femaleId.get(key)).getVoters().size();
<span style="white-space:pre">				</span>if (voteNum > maxVote)
<span style="white-space:pre">				</span>{
<span style="white-space:pre">					</span>maxVote = voteNum;
<span style="white-space:pre">					</span>femaleGodId = key.intValue();
<span style="white-space:pre">				</span>} else
<span style="white-space:pre">				</span>if (voteNum == maxVote)
<span style="white-space:pre">				</span>{
<span style="white-space:pre">					</span>int competiorQuality = ((Person)randomFemaleMap.get(key)).getTotalQuality();
<span style="white-space:pre">					</span>int femaleGodQuality = ((Person)randomFemaleMap.get(Integer.valueOf(femaleGodId))).getTotalQuality();
<span style="white-space:pre">					</span>if (competiorQuality > femaleGodQuality)
<span style="white-space:pre">					</span>{
<span style="white-space:pre">						</span>maxVote = voteNum;
<span style="white-space:pre">						</span>femaleGodId = key.intValue();
<span style="white-space:pre">					</span>} else
<span style="white-space:pre">					</span>if (competiorQuality == femaleGodQuality && key.intValue() < femaleGodId)
<span style="white-space:pre">					</span>{
<span style="white-space:pre">						</span>maxVote = voteNum;
<span style="white-space:pre">						</span>femaleGodId = key.intValue();
<span style="white-space:pre">					</span>}
<span style="white-space:pre">				</span>}
<span style="white-space:pre">			</span>}


<span style="white-space:pre">			</span>femaleGodSet.add(Integer.valueOf(femaleGodId));
<span style="white-space:pre">			</span>Person god = (Person)randomFemaleMap.get(Integer.valueOf(femaleGodId));
<span style="white-space:pre">			</span>int maleGodId;
<span style="white-space:pre">			</span>for (maleGodId = god.pollGod(); maleGodSet.contains(Integer.valueOf(maleGodId)) || ((Person)randomMaleMap.get(Integer.valueOf(maleGodId))).peekGod() != femaleGodId; maleGodId = god.pollGod());
<span style="white-space:pre">			</span>maleGodSet.add(Integer.valueOf(maleGodId));
<span style="white-space:pre">			</span>if (femaleGodId == -1)
<span style="white-space:pre">			</span>{
<span style="white-space:pre">				</span>sb.append((new StringBuilder()).append(randomMaleMap.get(Integer.valueOf(maleGodId))).append(" <--> ").append(randomFemaleMap.get(Integer.valueOf(femaleGodId))).append("\n").toString());
<span style="white-space:pre">				</span>return sb.toString();
<span style="white-space:pre">			</span>}
<span style="white-space:pre">			</span>ArrayList voters = ((Vote)femaleId.get(Integer.valueOf(femaleGodId))).getVoters();
<span style="white-space:pre">			</span>for (Iterator iterator11 = voters.iterator(); iterator11.hasNext();)
<span style="white-space:pre">			</span>{
<span style="white-space:pre">				</span>Person voter = (Person)iterator11.next();
<span style="white-space:pre">				</span>if (voter.getId() != maleGodId)
<span style="white-space:pre">				</span>{
<span style="white-space:pre">					</span>voter.pollGod();
<span style="white-space:pre">					</span>int nextGodId;
<span style="white-space:pre">					</span>for (nextGodId = voter.peekGod(); femaleGodSet.contains(Integer.valueOf(nextGodId)); nextGodId = voter.peekGod())
<span style="white-space:pre">						</span>voter.pollGod();


<span style="white-space:pre">					</span>if (femaleId.containsKey(Integer.valueOf(nextGodId)))
<span style="white-space:pre">					</span>{
<span style="white-space:pre">						</span>Vote vote = (Vote)femaleId.get(Integer.valueOf(nextGodId));
<span style="white-space:pre">						</span>vote.addVoter(voter);
<span style="white-space:pre">					</span>} else
<span style="white-space:pre">					</span>{
<span style="white-space:pre">						</span>Vote vote = new Vote();
<span style="white-space:pre">						</span>vote.setId(nextGodId);
<span style="white-space:pre">						</span>vote.addVoter(voter);
<span style="white-space:pre">						</span>femaleId.put(Integer.valueOf(nextGodId), vote);
<span style="white-space:pre">					</span>}
<span style="white-space:pre">				</span>}
<span style="white-space:pre">			</span>}


<span style="white-space:pre">			</span>femaleId.remove(Integer.valueOf(femaleGodId));
<span style="white-space:pre">		</span>} while (true);
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>public String play()
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>StringBuilder sb = new StringBuilder();
<span style="white-space:pre">		</span>for (Iterator iterator = maleMap.keySet().iterator(); iterator.hasNext();)
<span style="white-space:pre">		</span>{
<span style="white-space:pre">			</span>Integer maleId = (Integer)iterator.next();
<span style="white-space:pre">			</span>Person male = (Person)maleMap.get(maleId);
<span style="white-space:pre">			</span>Person female;
<span style="white-space:pre">			</span>for (Iterator iterator2 = femaleMap.keySet().iterator(); iterator2.hasNext(); female.judgePerson(male))
<span style="white-space:pre">			</span>{
<span style="white-space:pre">				</span>Integer femaleId = (Integer)iterator2.next();
<span style="white-space:pre">				</span>female = (Person)femaleMap.get(femaleId);
<span style="white-space:pre">				</span>male.judgePerson(female);
<span style="white-space:pre">			</span>}


<span style="white-space:pre">		</span>}


<span style="white-space:pre">		</span>int num = 1;
<span style="white-space:pre">		</span>for (Iterator iterator1 = playerList.iterator(); iterator1.hasNext();)
<span style="white-space:pre">		</span>{
<span style="white-space:pre">			</span>Person player = (Person)iterator1.next();
<span style="white-space:pre">			</span>if (player.getGender() == 1)
<span style="white-space:pre">			</span>{
<span style="white-space:pre">				</span>maleMap.put(Integer.valueOf(player.getId()), player);
<span style="white-space:pre">				</span>HashSet maleGodSet = new HashSet();
<span style="white-space:pre">				</span>HashSet femaleGodSet = new HashSet();
<span style="white-space:pre">				</span>Person female;
<span style="white-space:pre">				</span>for (Iterator iterator3 = femaleMap.keySet().iterator(); iterator3.hasNext(); female.changePlayer(player))
<span style="white-space:pre">				</span>{
<span style="white-space:pre">					</span>Integer femaleId = (Integer)iterator3.next();
<span style="white-space:pre">					</span>female = (Person)femaleMap.get(femaleId);
<span style="white-space:pre">					</span>player.judgePerson(female);
<span style="white-space:pre">				</span>}


<span style="white-space:pre">				</span>Person male;
<span style="white-space:pre">				</span>for (Iterator iterator4 = maleMap.keySet().iterator(); iterator4.hasNext(); male.buildBackupPriorityQueue())
<span style="white-space:pre">				</span>{
<span style="white-space:pre">					</span>Integer maleId = (Integer)iterator4.next();
<span style="white-space:pre">					</span>male = (Person)maleMap.get(maleId);
<span style="white-space:pre">				</span>}


<span style="white-space:pre">				</span>HashMap votes = new HashMap();
<span style="white-space:pre">				</span>for (Iterator iterator7 = maleMap.keySet().iterator(); iterator7.hasNext();)
<span style="white-space:pre">				</span>{
<span style="white-space:pre">					</span>Integer maleId = (Integer)iterator7.next();
<span style="white-space:pre">					</span>Person male1 = (Person)maleMap.get(maleId);
<span style="white-space:pre">					</span>int femaleGodId = male1.peekGod();
<span style="white-space:pre">					</span>if (votes.containsKey(Integer.valueOf(femaleGodId)))
<span style="white-space:pre">					</span>{
<span style="white-space:pre">						</span>Vote vote = (Vote)votes.get(Integer.valueOf(femaleGodId));
<span style="white-space:pre">						</span>vote.addVoter(male1);
<span style="white-space:pre">					</span>} else
<span style="white-space:pre">					</span>{
<span style="white-space:pre">						</span>Vote vote = new Vote();
<span style="white-space:pre">						</span>vote.setId(femaleGodId);
<span style="white-space:pre">						</span>vote.addVoter(male1);
<span style="white-space:pre">						</span>votes.put(Integer.valueOf(femaleGodId), vote);
<span style="white-space:pre">					</span>}
<span style="white-space:pre">				</span>}


<span style="white-space:pre">				</span>do
<span style="white-space:pre">				</span>{
<span style="white-space:pre">					</span>int maxVote = 0x80000000;
<span style="white-space:pre">					</span>int femaleGodId = 0x80000000;
<span style="white-space:pre">					</span>for (Iterator iterator9 = votes.keySet().iterator(); iterator9.hasNext();)
<span style="white-space:pre">					</span>{
<span style="white-space:pre">						</span>Integer key = (Integer)iterator9.next();
<span style="white-space:pre">						</span>int voteNum = ((Vote)votes.get(key)).getVoters().size();
<span style="white-space:pre">						</span>if (voteNum > maxVote)
<span style="white-space:pre">						</span>{
<span style="white-space:pre">							</span>maxVote = voteNum;
<span style="white-space:pre">							</span>femaleGodId = key.intValue();
<span style="white-space:pre">						</span>} else
<span style="white-space:pre">						</span>if (voteNum == maxVote)
<span style="white-space:pre">						</span>{
<span style="white-space:pre">							</span>int competitorQuality = ((Person)femaleMap.get(key)).getTotalQuality();
<span style="white-space:pre">							</span>int femaleGodQuality = ((Person)femaleMap.get(Integer.valueOf(femaleGodId))).getTotalQuality();
<span style="white-space:pre">							</span>if (competitorQuality > femaleGodQuality)
<span style="white-space:pre">							</span>{
<span style="white-space:pre">								</span>maxVote = voteNum;
<span style="white-space:pre">								</span>femaleGodId = key.intValue();
<span style="white-space:pre">							</span>} else
<span style="white-space:pre">							</span>if (competitorQuality == femaleGodQuality && key.intValue() < femaleGodId)
<span style="white-space:pre">							</span>{
<span style="white-space:pre">								</span>maxVote = voteNum;
<span style="white-space:pre">								</span>femaleGodId = key.intValue();
<span style="white-space:pre">							</span>}
<span style="white-space:pre">						</span>}
<span style="white-space:pre">					</span>}


<span style="white-space:pre">					</span>femaleGodSet.add(Integer.valueOf(femaleGodId));
<span style="white-space:pre">					</span>Person femaleGod = (Person)femaleMap.get(Integer.valueOf(femaleGodId));
<span style="white-space:pre">					</span>int maleGodId;
<span style="white-space:pre">					</span>for (maleGodId = femaleGod.pollGod(); maleGodSet.contains(Integer.valueOf(maleGodId)) || ((Person)maleMap.get(Integer.valueOf(maleGodId))).peekGod() != femaleGodId; maleGodId = femaleGod.pollGod());
<span style="white-space:pre">					</span>maleGodSet.add(Integer.valueOf(maleGodId));
<span style="white-space:pre">					</span>if (maleGodId == -1)
<span style="white-space:pre">					</span>{
<span style="white-space:pre">						</span>sb.append((new StringBuilder("[")).append(num++).append("] ").append(maleMap.get(Integer.valueOf(maleGodId))).append(" <--> ").append(femaleMap.get(Integer.valueOf(femaleGodId))).append("\n").toString());
<span style="white-space:pre">						</span>break;
<span style="white-space:pre">					</span>}
<span style="white-space:pre">					</span>if (maleGodSet.size() >= 100)
<span style="white-space:pre">					</span>{
<span style="white-space:pre">						</span>sb.append((new StringBuilder("[")).append(num++).append("] ").append("配对失败").append("\n").toString());
<span style="white-space:pre">						</span>break;
<span style="white-space:pre">					</span>}
<span style="white-space:pre">					</span>ArrayList voters = ((Vote)votes.get(Integer.valueOf(femaleGodId))).getVoters();
<span style="white-space:pre">					</span>for (Iterator iterator11 = voters.iterator(); iterator11.hasNext();)
<span style="white-space:pre">					</span>{
<span style="white-space:pre">						</span>Person voter = (Person)iterator11.next();
<span style="white-space:pre">						</span>if (voter.getId() != maleGodId)
<span style="white-space:pre">						</span>{
<span style="white-space:pre">							</span>voter.pollGod();
<span style="white-space:pre">							</span>int nextGodId;
<span style="white-space:pre">							</span>for (nextGodId = voter.peekGod(); femaleGodSet.contains(Integer.valueOf(nextGodId)); nextGodId = voter.peekGod())
<span style="white-space:pre">								</span>voter.pollGod();


<span style="white-space:pre">							</span>if (votes.containsKey(Integer.valueOf(nextGodId)))
<span style="white-space:pre">							</span>{
<span style="white-space:pre">								</span>Vote vote = (Vote)votes.get(Integer.valueOf(nextGodId));
<span style="white-space:pre">								</span>vote.addVoter(voter);
<span style="white-space:pre">							</span>} else
<span style="white-space:pre">							</span>{
<span style="white-space:pre">								</span>Vote vote = new Vote();
<span style="white-space:pre">								</span>vote.setId(nextGodId);
<span style="white-space:pre">								</span>vote.addVoter(voter);
<span style="white-space:pre">								</span>votes.put(Integer.valueOf(nextGodId), vote);
<span style="white-space:pre">							</span>}
<span style="white-space:pre">						</span>}
<span style="white-space:pre">					</span>}


<span style="white-space:pre">					</span>votes.remove(Integer.valueOf(femaleGodId));
<span style="white-space:pre">				</span>} while (true);
<span style="white-space:pre">				</span>maleMap.remove(Integer.valueOf(player.getId()));
<span style="white-space:pre">			</span>} else
<span style="white-space:pre">			</span>{
<span style="white-space:pre">				</span>femaleMap.put(Integer.valueOf(player.getId()), player);
<span style="white-space:pre">				</span>HashSet maleGodSet = new HashSet();
<span style="white-space:pre">				</span>HashSet femaleGodSet = new HashSet();
<span style="white-space:pre">				</span>Person male;
<span style="white-space:pre">				</span>for (Iterator iterator5 = maleMap.keySet().iterator(); iterator5.hasNext(); male.changePlayer(player))
<span style="white-space:pre">				</span>{
<span style="white-space:pre">					</span>Integer maleId = (Integer)iterator5.next();
<span style="white-space:pre">					</span>male = (Person)maleMap.get(maleId);
<span style="white-space:pre">					</span>player.judgePerson(male);
<span style="white-space:pre">				</span>}


<span style="white-space:pre">				</span>Person female;
<span style="white-space:pre">				</span>for (Iterator iterator6 = femaleMap.keySet().iterator(); iterator6.hasNext(); female.buildBackupPriorityQueue())
<span style="white-space:pre">				</span>{
<span style="white-space:pre">					</span>Integer femaleId = (Integer)iterator6.next();
<span style="white-space:pre">					</span>female = (Person)femaleMap.get(femaleId);
<span style="white-space:pre">				</span>}


<span style="white-space:pre">				</span>HashMap votes = new HashMap();
<span style="white-space:pre">				</span>for (Iterator iterator8 = maleMap.keySet().iterator(); iterator8.hasNext();)
<span style="white-space:pre">				</span>{
<span style="white-space:pre">					</span>Integer maleId = (Integer)iterator8.next();
<span style="white-space:pre">					</span>Person male1 = (Person)maleMap.get(maleId);
<span style="white-space:pre">					</span>int femaleGodId = male1.peekGod();
<span style="white-space:pre">					</span>if (votes.containsKey(Integer.valueOf(femaleGodId)))
<span style="white-space:pre">					</span>{
<span style="white-space:pre">						</span>Vote vote = (Vote)votes.get(Integer.valueOf(femaleGodId));
<span style="white-space:pre">						</span>vote.addVoter(male1);
<span style="white-space:pre">					</span>} else
<span style="white-space:pre">					</span>{
<span style="white-space:pre">						</span>Vote vote = new Vote();
<span style="white-space:pre">						</span>vote.setId(femaleGodId);
<span style="white-space:pre">						</span>vote.addVoter(male1);
<span style="white-space:pre">						</span>votes.put(Integer.valueOf(femaleGodId), vote);
<span style="white-space:pre">					</span>}
<span style="white-space:pre">				</span>}


<span style="white-space:pre">				</span>do
<span style="white-space:pre">				</span>{
<span style="white-space:pre">					</span>int maxVote = 0x80000000;
<span style="white-space:pre">					</span>int femaleGodId = 0x80000000;
<span style="white-space:pre">					</span>for (Iterator iterator10 = votes.keySet().iterator(); iterator10.hasNext();)
<span style="white-space:pre">					</span>{
<span style="white-space:pre">						</span>Integer key = (Integer)iterator10.next();
<span style="white-space:pre">						</span>int voteNum = ((Vote)votes.get(key)).getVoters().size();
<span style="white-space:pre">						</span>if (voteNum > maxVote)
<span style="white-space:pre">						</span>{
<span style="white-space:pre">							</span>maxVote = voteNum;
<span style="white-space:pre">							</span>femaleGodId = key.intValue();
<span style="white-space:pre">						</span>} else
<span style="white-space:pre">						</span>if (voteNum == maxVote)
<span style="white-space:pre">						</span>{
<span style="white-space:pre">							</span>int competiorQuality = ((Person)femaleMap.get(key)).getTotalQuality();
<span style="white-space:pre">							</span>int femaleGodQuality = ((Person)femaleMap.get(Integer.valueOf(femaleGodId))).getTotalQuality();
<span style="white-space:pre">							</span>if (competiorQuality > femaleGodQuality)
<span style="white-space:pre">							</span>{
<span style="white-space:pre">								</span>maxVote = voteNum;
<span style="white-space:pre">								</span>femaleGodId = key.intValue();
<span style="white-space:pre">							</span>} else
<span style="white-space:pre">							</span>if (competiorQuality == femaleGodQuality && key.intValue() < femaleGodId)
<span style="white-space:pre">							</span>{
<span style="white-space:pre">								</span>maxVote = voteNum;
<span style="white-space:pre">								</span>femaleGodId = key.intValue();
<span style="white-space:pre">							</span>}
<span style="white-space:pre">						</span>}
<span style="white-space:pre">					</span>}


<span style="white-space:pre">					</span>femaleGodSet.add(Integer.valueOf(femaleGodId));
<span style="white-space:pre">					</span>Person god = (Person)femaleMap.get(Integer.valueOf(femaleGodId));
<span style="white-space:pre">					</span>int maleGodId;
<span style="white-space:pre">					</span>for (maleGodId = god.pollGod(); maleGodSet.contains(Integer.valueOf(maleGodId)) || ((Person)maleMap.get(Integer.valueOf(maleGodId))).peekGod() != femaleGodId; maleGodId = god.pollGod());
<span style="white-space:pre">					</span>maleGodSet.add(Integer.valueOf(maleGodId));
<span style="white-space:pre">					</span>if (femaleGodId == -1)
<span style="white-space:pre">					</span>{
<span style="white-space:pre">						</span>sb.append((new StringBuilder("[")).append(num++).append("] ").append(maleMap.get(Integer.valueOf(maleGodId))).append(" <--> ").append(femaleMap.get(Integer.valueOf(femaleGodId))).append("\n").toString());
<span style="white-space:pre">						</span>break;
<span style="white-space:pre">					</span>}
<span style="white-space:pre">					</span>if (maleGodSet.size() >= 100)
<span style="white-space:pre">					</span>{
<span style="white-space:pre">						</span>sb.append((new StringBuilder("[")).append(num++).append("] ").append("配对失败").append("\n").toString());
<span style="white-space:pre">						</span>break;
<span style="white-space:pre">					</span>}
<span style="white-space:pre">					</span>ArrayList voters = ((Vote)votes.get(Integer.valueOf(femaleGodId))).getVoters();
<span style="white-space:pre">					</span>for (Iterator iterator12 = voters.iterator(); iterator12.hasNext();)
<span style="white-space:pre">					</span>{
<span style="white-space:pre">						</span>Person voter = (Person)iterator12.next();
<span style="white-space:pre">						</span>if (voter.getId() != maleGodId)
<span style="white-space:pre">						</span>{
<span style="white-space:pre">							</span>voter.pollGod();
<span style="white-space:pre">							</span>int nextGodId;
<span style="white-space:pre">							</span>for (nextGodId = voter.peekGod(); femaleGodSet.contains(Integer.valueOf(nextGodId)); nextGodId = voter.peekGod())
<span style="white-space:pre">								</span>voter.pollGod();


<span style="white-space:pre">							</span>if (votes.containsKey(Integer.valueOf(nextGodId)))
<span style="white-space:pre">							</span>{
<span style="white-space:pre">								</span>Vote vote = (Vote)votes.get(Integer.valueOf(nextGodId));
<span style="white-space:pre">								</span>vote.addVoter(voter);
<span style="white-space:pre">							</span>} else
<span style="white-space:pre">							</span>{
<span style="white-space:pre">								</span>Vote vote = new Vote();
<span style="white-space:pre">								</span>vote.setId(nextGodId);
<span style="white-space:pre">								</span>vote.addVoter(voter);
<span style="white-space:pre">								</span>votes.put(Integer.valueOf(nextGodId), vote);
<span style="white-space:pre">							</span>}
<span style="white-space:pre">						</span>}
<span style="white-space:pre">					</span>}


<span style="white-space:pre">					</span>votes.remove(Integer.valueOf(femaleGodId));
<span style="white-space:pre">				</span>} while (true);
<span style="white-space:pre">				</span>femaleMap.remove(Integer.valueOf(player.getId()));
<span style="white-space:pre">			</span>}
<span style="white-space:pre">		</span>}


<span style="white-space:pre">		</span>return sb.toString();
<span style="white-space:pre">	</span>}
}
主类:
package jins.start;


public class MatchGame
{


<span style="white-space:pre">	</span>public MatchGame()
<span style="white-space:pre">	</span>{
<span style="white-space:pre">	</span>}


<span style="white-space:pre">	</span>public static void main(String args[])
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>new DengLu();
<span style="white-space:pre">	</span>}
}