一、标题: 数字化婚姻配对尝试 二、题目: 建立一个模型。来模拟推导社会男女择偶过程。 为了模型简化,一个人的特性指标有三个,这里如果为財富、样貌、品行。每一个指标均可取值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("username"); <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, "username不能为空!"); <span style="white-space:pre"> </span>} else if (passWord.getText().equals("")) { <span style="white-space:pre"> </span>JOptionPane.showMessageDialog(null, "password不能为空!"); <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, "password错误"); <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数字 ").toString()); <span style="white-space:pre"> </span>return false; <span style="white-space:pre"> </span>} <span style="white-space:pre"> </span>int value = Integer.parseInt(field.getText()); <span style="white-space:pre"> </span>if (value >= 1 && value <= 98) <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>return true; <span style="white-space:pre"> </span>} else <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>infoArea.append((new StringBuilder(String.valueOf(field.getName()))).append("输入错误,请输入1~98数字 ").toString()); <span style="white-space:pre"> </span>return false; <span style="white-space:pre"> </span>} <span style="white-space:pre"> </span>} else <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>infoArea.append((new StringBuilder(String.valueOf(field.getName()))).append("输入错误,请输入1~98数字 ").toString()); <span style="white-space:pre"> </span>return false; <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>this$0 = Frame.this; <span style="white-space:pre"> </span>//super(); <span style="white-space:pre"> </span>} <span style="white-space:pre"> </span>}; <span style="white-space:pre"> </span>JPanel mainPanel = new JPanel(); <span style="white-space:pre"> </span>mainPanel.setLayout(new BorderLayout()); <span style="white-space:pre"> </span>JTabbedPane westPanel = new JTabbedPane(); <span style="white-space:pre"> </span>JPanel manulPanel = new JPanel(); <span style="white-space:pre"> </span>Box mainBox = Box.createVerticalBox(); <span style="white-space:pre"> </span>Box genderBox = Box.createHorizontalBox(); <span style="white-space:pre"> </span>JLabel genderLabel = new JLabel("性别:"); <span style="white-space:pre"> </span>ButtonGroup group = new ButtonGroup(); <span style="white-space:pre"> </span>final JRadioButton maleButton = new JRadioButton("男", true); <span style="white-space:pre"> </span>group.add(maleButton); <span style="white-space:pre"> </span>JRadioButton femaleButton = new JRadioButton("女", false); <span style="white-space:pre"> </span>group.add(femaleButton); <span style="white-space:pre"> </span>genderBox.add(genderLabel); <span style="white-space:pre"> </span>genderBox.add(Box.createHorizontalStrut(10)); <span style="white-space:pre"> </span>genderBox.add(maleButton); <span style="white-space:pre"> </span>genderBox.add(Box.createHorizontalStrut(10)); <span style="white-space:pre"> </span>genderBox.add(femaleButton); <span style="white-space:pre"> </span>Box attributeBox = Box.createHorizontalBox(); <span style="white-space:pre"> </span>Box personalBox = Box.createVerticalBox(); <span style="white-space:pre"> </span>JLabel personalLabel = new JLabel("个人属性"); <span style="white-space:pre"> </span>Box fortuneBox = Box.createHorizontalBox(); <span style="white-space:pre"> </span>JLabel fortuneLabel = new JLabel("財富:"); <span style="white-space:pre"> </span>final JFormattedTextField fortuneField = new JFormattedTextField(NumberFormat.getInstance()); <span style="white-space:pre"> </span>fortuneField.setName("个人属性(財富)"); <span style="white-space:pre"> </span>fortuneField.setSize(100, 100); <span style="white-space:pre"> </span>fortuneField.setInputVerifier(verifier); <span style="white-space:pre"> </span>fortuneBox.add(fortuneLabel); <span style="white-space:pre"> </span>fortuneBox.add(Box.createHorizontalStrut(10)); <span style="white-space:pre"> </span>fortuneBox.add(fortuneField); <span style="white-space:pre"> </span>Box appearanceBox = Box.createHorizontalBox(); <span style="white-space:pre"> </span>JLabel appearanceLabel = new JLabel("外貌:"); <span style="white-space:pre"> </span>final JFormattedTextField appearanceField = new JFormattedTextField(NumberFormat.getInstance()); <span style="white-space:pre"> </span>appearanceField.setName("个人属性(外貌)"); <span style="white-space:pre"> </span>appearanceField.setInputVerifier(verifier); <span style="white-space:pre"> </span>appearanceBox.add(appearanceLabel); <span style="white-space:pre"> </span>appearanceBox.add(Box.createHorizontalStrut(10)); <span style="white-space:pre"> </span>appearanceBox.add(appearanceField); <span style="white-space:pre"> </span>Box charactoreBox = Box.createHorizontalBox(); <span style="white-space:pre"> </span>JLabel charactorLabel = new JLabel("品行:"); <span style="white-space:pre"> </span>final JFormattedTextField charactorField = new JFormattedTextField(NumberFormat.getInstance()); <span style="white-space:pre"> </span>charactorField.setName("个人属性(品行)"); <span style="white-space:pre"> </span>charactorField.setInputVerifier(verifier); <span style="white-space:pre"> </span>charactoreBox.add(charactorLabel); <span style="white-space:pre"> </span>charactoreBox.add(Box.createHorizontalStrut(10)); <span style="white-space:pre"> </span>charactoreBox.add(charactorField); <span style="white-space:pre"> </span>personalBox.add(personalLabel); <span style="white-space:pre"> </span>personalBox.add(Box.createVerticalStrut(20)); <span style="white-space:pre"> </span>personalBox.add(fortuneBox); <span style="white-space:pre"> </span>personalBox.add(Box.createVerticalStrut(20)); <span style="white-space:pre"> </span>personalBox.add(appearanceBox); <span style="white-space:pre"> </span>personalBox.add(Box.createVerticalStrut(20)); <span style="white-space:pre"> </span>personalBox.add(charactoreBox); <span style="white-space:pre"> </span>Box requireBox = Box.createVerticalBox(); <span style="white-space:pre"> </span>JLabel requireLabel = new JLabel("需求属性"); <span style="white-space:pre"> </span>Box requireFortuneBox = Box.createHorizontalBox(); <span style="white-space:pre"> </span>JLabel requireFortuneLabel = new JLabel("財富:"); <span style="white-space:pre"> </span>final JFormattedTextField requireFortuneField = new JFormattedTextField(NumberFormat.getInstance()); <span style="white-space:pre"> </span>requireFortuneField.setName("需求属性(財富)"); <span style="white-space:pre"> </span>requireFortuneField.setInputVerifier(verifier); <span style="white-space:pre"> </span>requireFortuneBox.add(requireFortuneLabel); <span style="white-space:pre"> </span>requireFortuneBox.add(Box.createHorizontalStrut(10)); <span style="white-space:pre"> </span>requireFortuneBox.add(requireFortuneField); <span style="white-space:pre"> </span>Box requireAppearanceBox = Box.createHorizontalBox(); <span style="white-space:pre"> </span>JLabel requireAppearanceLabel = new JLabel("外貌:"); <span style="white-space:pre"> </span>final JFormattedTextField requireAppearanceField = new JFormattedTextField(NumberFormat.getInstance()); <span style="white-space:pre"> </span>requireAppearanceField.setName("需求属性(外貌)"); <span style="white-space:pre"> </span>requireAppearanceField.setInputVerifier(verifier); <span style="white-space:pre"> </span>requireAppearanceBox.add(requireAppearanceLabel); <span style="white-space:pre"> </span>requireAppearanceBox.add(Box.createHorizontalStrut(10)); <span style="white-space:pre"> </span>requireAppearanceBox.add(requireAppearanceField); <span style="white-space:pre"> </span>Box requireCharactoreBox = Box.createHorizontalBox(); <span style="white-space:pre"> </span>JLabel requireCharactorLabel = new JLabel("品行:"); <span style="white-space:pre"> </span>final JFormattedTextField requireCharactorField = new JFormattedTextField(NumberFormat.getInstance()); <span style="white-space:pre"> </span>requireCharactorField.setName("需求属性(品行)"); <span style="white-space:pre"> </span>requireCharactorField.setInputVerifier(verifier); <span style="white-space:pre"> </span>requireCharactoreBox.add(requireCharactorLabel); <span style="white-space:pre"> </span>requireCharactoreBox.add(Box.createHorizontalStrut(10)); <span style="white-space:pre"> </span>requireCharactoreBox.add(requireCharactorField); <span style="white-space:pre"> </span>requireBox.add(requireLabel); <span style="white-space:pre"> </span>requireBox.add(Box.createVerticalStrut(20)); <span style="white-space:pre"> </span>requireBox.add(requireFortuneBox); <span style="white-space:pre"> </span>requireBox.add(Box.createVerticalStrut(20)); <span style="white-space:pre"> </span>requireBox.add(requireAppearanceBox); <span style="white-space:pre"> </span>requireBox.add(Box.createVerticalStrut(20)); <span style="white-space:pre"> </span>requireBox.add(requireCharactoreBox); <span style="white-space:pre"> </span>attributeBox.add(personalBox); <span style="white-space:pre"> </span>attributeBox.add(Box.createHorizontalStrut(40)); <span style="white-space:pre"> </span>attributeBox.add(requireBox); <span style="white-space:pre"> </span>Box buttonBox = Box.createHorizontalBox(); <span style="white-space:pre"> </span>JButton confirm = new JButton("确定"); <span style="white-space:pre"> </span>confirm.addActionListener(new ActionListener() { <span style="white-space:pre"> </span> <span style="white-space:pre"> </span>@Override <span style="white-space:pre"> </span>public void actionPerformed(ActionEvent e) { <span style="white-space:pre"> </span>// TODO Auto-generated method stub <span style="white-space:pre"> </span>if (!fortuneField.isEditValid() || fortuneField.getText().equals("")) <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>infoArea.append((new StringBuilder(String.valueOf(fortuneField.getName()))).append("输入错误,请输入1~98数字 ").toString()); <span style="white-space:pre"> </span>return; <span style="white-space:pre"> </span>} <span style="white-space:pre"> </span>if (!appearanceField.isEditValid() || appearanceField.getText().equals("")) <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>infoArea.append((new StringBuilder(String.valueOf(appearanceField.getName()))).append("输入错误,请输入1~98数字 ").toString()); <span style="white-space:pre"> </span>return; <span style="white-space:pre"> </span>} <span style="white-space:pre"> </span>if (!charactorField.isEditValid() || charactorField.getText().equals("")) <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>infoArea.append((new StringBuilder(String.valueOf(charactorField.getName()))).append("输入错误,请输入1~98数字 ").toString()); <span style="white-space:pre"> </span>return; <span style="white-space:pre"> </span>} <span style="white-space:pre"> </span>int requireFortune = -200; <span style="white-space:pre"> </span>int requireAppearance = -200; <span style="white-space:pre"> </span>int requireCharactor = -200; <span style="white-space:pre"> </span>if (!requireFortuneField.isEditValid() || requireFortuneField.getText().equals("")) <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>infoArea.append((new StringBuilder(String.valueOf(requireFortuneField.getName()))).append("输入错误,请输入1~98数字 ").toString()); <span style="white-space:pre"> </span>return; <span style="white-space:pre"> </span>} <span style="white-space:pre"> </span>requireFortune = Integer.parseInt(requireFortuneField.getText()); <span style="white-space:pre"> </span>if (!requireAppearanceField.isEditValid() || requireAppearanceField.getText().equals("")) <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>infoArea.append((new StringBuilder(String.valueOf(requireAppearanceField.getName()))).append("输入错误,请输入1~98数字 ").toString()); <span style="white-space:pre"> </span>return; <span style="white-space:pre"> </span>} <span style="white-space:pre"> </span>requireAppearance = Integer.parseInt(requireAppearanceField.getText()); <span style="white-space:pre"> </span>if (!requireCharactorField.isEditValid() || requireCharactorField.getText().equals("")) <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>infoArea.append((new StringBuilder(String.valueOf(requireCharactorField.getName()))).append("输入错误,请输入1~98数字 ").toString()); <span style="white-space:pre"> </span>return; <span style="white-space:pre"> </span>} <span style="white-space:pre"> </span>requireCharactor = Integer.parseInt(requireCharactorField.getText()); <span style="white-space:pre"> </span>if (requireFortune + requireAppearance + requireCharactor != 100) <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>infoArea.append("需求属性之和(財富+外貌+品行)必须为100 "); <span style="white-space:pre"> </span>} else <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>int gender = maleButton.isSelected() ? 1 : 0; <span style="white-space:pre"> </span>infoArea.append("产生随机样本... "); <span style="white-space:pre"> </span>infoArea.append(activity.generate(gender)); <span style="white-space:pre"> </span>infoArea.append("样本生成完成 "); <span style="white-space:pre"> </span>infoArea.append("匹配结果: "); <span style="white-space:pre"> </span>infoArea.append(activity.join(new Person(-1, gender, Integer.parseInt(fortuneField.getText()), Integer.parseInt(appearanceField.getText()), Integer.parseInt(charactorField.getText()), requireFortune, requireAppearance, requireCharactor))); <span style="white-space:pre"> </span>infoArea.append(" "); <span style="white-space:pre"> </span>} <span style="white-space:pre"> </span>} <span style="white-space:pre"> </span>}); <span style="white-space:pre"> </span>JButton clear1 = new JButton("清空信息"); <span style="white-space:pre"> </span>clear1.addActionListener(new ActionListener() { <span style="white-space:pre"> </span>final Frame this$0; <span style="white-space:pre"> </span>public void actionPerformed(ActionEvent arg0) <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>infoArea.setText(""); <span style="white-space:pre"> </span>} <span style="white-space:pre"> </span> <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>this$0 = Frame.this; <span style="white-space:pre"> </span>//super(); <span style="white-space:pre"> </span>} <span style="white-space:pre"> </span>}); <span style="white-space:pre"> </span>buttonBox.add(confirm); <span style="white-space:pre"> </span>buttonBox.add(Box.createHorizontalStrut(40)); <span style="white-space:pre"> </span>buttonBox.add(clear1); <span style="white-space:pre"> </span>mainBox.add(genderBox); <span style="white-space:pre"> </span>mainBox.add(Box.createVerticalStrut(20)); <span style="white-space:pre"> </span>mainBox.add(attributeBox); <span style="white-space:pre"> </span>mainBox.add(Box.createVerticalStrut(20)); <span style="white-space:pre"> </span>mainBox.add(buttonBox); <span style="white-space:pre"> </span>manulPanel.add(mainBox); <span style="white-space:pre"> </span>JScrollPane manulPane = new JScrollPane(mainBox); <span style="white-space:pre"> </span>westPanel.add("手动输入演示", manulPane); <span style="white-space:pre"> </span>JPanel autoPanel = new JPanel(); <span style="white-space:pre"> </span>autoPanel.setLayout(new FlowLayout()); <span style="white-space:pre"> </span>JButton start = new JButton("開始"); <span style="white-space:pre"> </span>start.addActionListener(new ActionListener() { <span style="white-space:pre"> </span>final Frame this$0; <span style="white-space:pre"> </span>public void actionPerformed(ActionEvent arg0) <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>infoArea.append("100位主角匹配结果例如以下: "); <span style="white-space:pre"> </span>infoArea.append(activity.play()); <span style="white-space:pre"> </span>} <span style="white-space:pre"> </span> <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>this$0 = Frame.this; <span style="white-space:pre"> </span>//super(); <span style="white-space:pre"> </span>} <span style="white-space:pre"> </span>}); <span style="white-space:pre"> </span>autoPanel.add(start); <span style="white-space:pre"> </span>JButton clear2 = new JButton("清空信息"); <span style="white-space:pre"> </span>clear2.addActionListener(new ActionListener() { <span style="white-space:pre"> </span>final Frame this$0; <span style="white-space:pre"> </span>public void actionPerformed(ActionEvent arg0) <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>infoArea.setText(""); <span style="white-space:pre"> </span>} <span style="white-space:pre"> </span> <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>this$0 = Frame.this; <span style="white-space:pre"> </span>//super(); <span style="white-space:pre"> </span>} <span style="white-space:pre"> </span>}); <span style="white-space:pre"> </span>autoPanel.add(clear2); <span style="white-space:pre"> </span>westPanel.add("加载样本演示", autoPanel); <span style="white-space:pre"> </span>infoArea = new JTextArea(20, 35); <span style="white-space:pre"> </span>infoArea.setLineWrap(true); <span style="white-space:pre"> </span>infoArea.setEditable(false); <span style="white-space:pre"> </span>JScrollPane eastPanel = new JScrollPane(infoArea); <span style="white-space:pre"> </span>mainPanel.add(westPanel, "West"); <span style="white-space:pre"> </span>mainPanel.add(eastPanel, "East"); <span style="white-space:pre"> </span>frame.add(mainPanel); <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>} }
</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("男生 女生 "); <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(" ").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(" ").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(" ")).append(female).append(" ").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(" ").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(" ").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(" ").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(" ").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(" ").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(" ").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(" ").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>} }
版权声明:本文博客原创文章。博客,未经同意,不得转载。