| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 481 人关注过本帖
标题:soft_wind进
只看楼主 加入收藏
myajax95
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:30
帖 子:2978
专家分:0
注 册:2006-3-5
收藏
 问题点数:0 回复次数:2 
soft_wind进

程序可以写的更标准点,但俺这里已经夜里2点了,回头再修正吧。没什么算法,就是把点们从作到又排列一下,吃完的跳过,两个PAC MAN各来吃一次。
http://www.bc-cn.net/bbs/dispbbs.asp?boardid=5&id=63515&star=1#135076
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;

class CPoint
{
public:
CPoint(int x=0, int y=0) :m_intX(x), m_intY(y) {}
int GetX() {return m_intX;}
int GetY() {return m_intY;}
bool CanConnect(CPoint p) { return(GetX() <= p.GetX() && GetY() <= p.GetY());}
private:
int m_intX;
int m_intY;
};

bool ComparePointPosition(CPoint p1, CPoint p2)
{
return p1.GetX() < p2.GetX();
}

int main(int argc, char* argv[])
{
CPoint BeanPoints[] =
{
CPoint(8, 1),
CPoint(1, 5),
CPoint(5, 7),
CPoint(2, 2),
CPoint(7, 8),
CPoint(4, 6),
CPoint(3, 3),
CPoint(6, 4)
};
CPoint *pCurrent;
const int intBeanNum = sizeof(BeanPoints) / sizeof(CPoint);
long lTryCount1, lTryCount2, lCurrentTry, lTryTimes = pow(2, intBeanNum);
int intEatenBeanNum, intPointCount, intMaxEaten = 0;
bool intPointStatus[intBeanNum]; // eaten or not, true is eaten

sort(&BeanPoints[0], &BeanPoints[8], ComparePointPosition);

// man 1
for (lTryCount1 = 0; lTryCount1 < lTryTimes; lTryCount1++)
{
intEatenBeanNum = 0;

pCurrent = &BeanPoints[0];
lCurrentTry = lTryCount1;
// init eaten point array.
for (intPointCount = 0; intPointCount < intBeanNum; intPointCount++)
intPointStatus[intPointCount] = false;

for (intPointCount = 0; intPointCount < intBeanNum; intPointCount++)
{
if (lCurrentTry % 2 && intPointStatus[intPointCount] == false)
{
// this point in count.
if (intEatenBeanNum == 0 || pCurrent->CanConnect(BeanPoints[intPointCount]))
{
pCurrent = &BeanPoints[intPointCount];
intPointStatus[intPointCount] = true;
intEatenBeanNum ++;
}
}
lCurrentTry /= 2;
}
// man 2, not status clean up
for (lTryCount2 = 0; lTryCount2 < lTryTimes; lTryCount2++)
{
lCurrentTry = lTryCount2;
pCurrent = &BeanPoints[0];
for (intPointCount = 0; intPointCount < intBeanNum; intPointCount++)
{
if (lCurrentTry % 2 && intPointStatus[intPointCount] == false)
{
// this point in count.
if (intEatenBeanNum == 0 || pCurrent->CanConnect(BeanPoints[intPointCount]))
{
pCurrent = &BeanPoints[intPointCount];
intPointStatus[intPointCount] = true;
intEatenBeanNum ++;
}
}
lCurrentTry /= 2;
}
}
if (intMaxEaten < intEatenBeanNum)
intMaxEaten = intEatenBeanNum;
}

cout << "PAC Man ate " << intMaxEaten << " beans\n";
return 0;
}

搜索更多相关主题的帖子: wind soft 
2006-05-14 17:10
soft_wind
Rank: 3Rank: 3
等 级:新手上路
威 望:8
帖 子:1430
专家分:0
注 册:2006-4-5
收藏
得分:0 
先谢谢了再看!!!!

对不礼貌的女生收钱......
2006-05-14 17:21
soft_wind
Rank: 3Rank: 3
等 级:新手上路
威 望:8
帖 子:1430
专家分:0
注 册:2006-4-5
收藏
得分:0 
啊……,真的看不懂......
看来得好好学C++了,
我刚开始看C++,
不好意思...
不过还是谢谢了.
我先把您的代码拷过来再说,呵呵,谢谢

对不礼貌的女生收钱......
2006-05-14 17:24
快速回复:soft_wind进
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.043939 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved