⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 greedyselect1dlg.cpp

📁 贪心法会议安排
💻 CPP
字号:
// GREEDYSELECT1Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "GREEDYSELECT1.h"
#include "GREEDYSELECT1Dlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGREEDYSELECT1Dlg dialog

CGREEDYSELECT1Dlg::CGREEDYSELECT1Dlg(CWnd* pParent /*=NULL*/)
	: CDialog(CGREEDYSELECT1Dlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CGREEDYSELECT1Dlg)
	Roomarrange = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CGREEDYSELECT1Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CGREEDYSELECT1Dlg)
	DDX_Text(pDX, IDC_EDIT1, Roomarrange);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CGREEDYSELECT1Dlg, CDialog)
	//{{AFX_MSG_MAP(CGREEDYSELECT1Dlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGREEDYSELECT1Dlg message handlers

BOOL CGREEDYSELECT1Dlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	Timebe[0][0]=1;//
    Timebe[0][1]=2;
    Timebe[1][0] = 2;//
    Timebe[1][1] = 4;
    Timebe[2][0] = 3;
     Timebe[2][1] =5;
     Timebe[3][0]=4;//
Timebe[3][1]=6;
Timebe[4][0]   =5; 
Timebe[4][1]   =7; 
Timebe[5][0] =6;//
Timebe[5][1]=8;
Timebe[6][0]=7;
Timebe[6][1]=9;
Timebe[7][0]=7;
Timebe[7][1]=10;   
ActNumber=8;//
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CGREEDYSELECT1Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CGREEDYSELECT1Dlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CGREEDYSELECT1Dlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CGREEDYSELECT1Dlg::OnButton2() 
{
	// TODO: Add your control notification handler code here
int NumberRoom;
int Tend;//当前活动结束时间
int arranged;// 以安排活动个数
int j;

NumberRoom=1;
Use[0]=1;
arranged=1;
Tend=Timebe[0][1];
for (int i=1;i<100;i++)
Use[i]=0;
i=1;
while( arranged<=ActNumber)
{
for(;i<ActNumber;i++)//开第NumberRoom个房间并安排会议
{
	if (Tend<=Timebe[i][0])
	{
		Use[i]=NumberRoom;
		Tend=Timebe[i][1];
		arranged++;
	}
}
   	
   for( j=0; (j<ActNumber ) && (Use[j] !=0);j++ ) ;// 找到第一个未安排的活动;
   if(arranged!=ActNumber)//未安排完
   {
   
	 ++NumberRoom;
	 arranged++;
	 Use[j]=NumberRoom;
	 Tend=Timebe[j][1];
	 i=j+1;
   } 
   else
	   break;
	 
		
}
     
CString str;
Roomarrange="";
for (i=0;i<ActNumber;i++)//ActNumber-1
{
int num1,num2;
num1=Timebe[i][0];
num2=Timebe[i][1]	;
str.Format(" %d %d %d;",num1,num2,Use[i]);          
Roomarrange=Roomarrange+str;
str="";
}


UpdateData(false);
str.Format("需要 %d个会议室",NumberRoom);
MessageBox(str);	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -