Big Bug Ban

兴趣 践行 创新

c++ 最稳定婚姻问题

 

/* marrage.cpp : 定义控制台应用程序的入口点。
 * author baizhongwei
 * website http://blog.webpcpp.net
 * 最稳定婚姻问题
 * create time 2009-12-15 16:17
 */

#include "stdafx.h"
#include 
#include 
#include 
#include 
#include "time.h"
using namespace std;
//好感度的类
class goodfeeling{
private:
	//对象编号
	int p_num;
	//好感度
	int g_degree;
public:
	goodfeeling(int people_num,int good_degree){
		g_degree=good_degree;
		p_num=people_num;
	}
	int getHot(){
		return g_degree;
	}
	int getPeoplenum(){
		return p_num;
	}
};
//用感觉度进行正向排序,
int imp(goodfeeling A,goodfeeling B){

	if(A.getHot()>=B.getHot())
		return 1;
	else
		return 0;
}
//用感觉度进行反向排序,
int reimp(goodfeeling A,goodfeeling B){

	if(A.getHot()>B.getHot())
		return 0;
	else
		return 1;
}
class people{

private:
	//好感表
	vector lovers;
	//是否正在约会
	int  meetting;
	//这个人的编号
	int num;
	//性别  男是1  女是0
	int sex;

	int metwho;
public:
	int getwho(){
		return this->metwho;
	}
	int getsex(){
		return sex;
	}
	int getnum(){
		return num;
	}
	//构造函数
	people(int num,int sex){
		this->num=num;
		this->sex=sex;
		this->meetting=0;
		this->metwho=0;
	}
	//是否正在约会
	bool isMeeting(){
		return meetting;
	}
	//让他去约会sb.
	bool gomet(people m){
		if(isMeeting())
		{
			cout<<"女孩正在和"<gethotnum(metwho))
			{
				int old=metwho;
				metwho=m.getnum();
				//抛弃以前那个
				throw int(old);
			}
			else{
				//约见失败
				return false;
			}
		}
		else
		{

			meetting=1;

			metwho=m.getnum();
		}
		//成功约会
		return true;
	}
	//设定感觉系数
	int setfeel(goodfeeling num){
		//对象的序号
		lovers.insert(lovers.end(),num);
		//根据好感度排序已有的人物
		sort(lovers.begin(),lovers.end(),imp);

		return 1;

	}
	int gethotnum(int p){

		for(int i=0;i gun;

	gun.push(boy[0]);

	gun.push(boy[1]);

	gun.push(boy[2]);
	int i=0;

	while(!gun.empty()&&i++<20)
	{
		//让队首小男孩去见梦中情人
		int t=meeting(gun.front(),girl[gun.front().getHotestlover()-1]);

		if(t!=0&&t!=99)
		{
			//让被抛弃的男孩重回光棍队列
			boy[t-1].setfree(gun.front().getHotestlover());
			gun.push(boy[t-1]);
		}
		//如果是被抛弃的..入队..
		if(t==99)
		{
			gun.front().setfree(gun.front().getHotestlover());
		}
		if(gun.front().isMeeting())
		{
			boy[gun.front().getnum()-1]=gun.front();
			gun.pop();
		}
	}
	cout<<"----------------------"<

Written by princehaku

12月 16th, 2009 at 4:58 下午

Posted in c/c++

without comments

Leave a Reply