|
怎么连 主函数 都找不到,你怎么编译成功的,,,
disable 发表于 2010-5-6 18:09
那个代码是VS2005下的,你的编译器要是VC6 要改成这样,其实看下error信息,网上搜下就可以改对了。
#include <vector>
#include <string>
#include <limits>
#include <iostream>
using namespace std;
struct Point
{
int m_nPoint;
int m_nValue;
string m_szoper;
public:
Point(int nPoint, int nValue, string szoper) : m_nPoint(nPoint), m_nValue(nValue), m_szoper(szoper){}
};
int main(int argc, char* argv[])
{
int nStart; // 起始值
int nEnd; // 结束值
int nCost_Add; // +2 价值量
int nCost_Del; // -2 价值量
int nCost_Mul; // *2 价值量
cout << "起始值: ";
cin >> nStart;
cout << "目标值: ";
cin >> nEnd;
cout << "+2 价值量: ";
cin >> nCost_Add;
cout << "-2 价值量: ";
cin >> nCost_Del;
cout << "*2 价值量: ";
cin >> nCost_Mul;
// 初始状态
vector<Point> vecOperate;
vecOperate.push_back(Point(nStart, 0, ""));
Point sOptimalSolution(nEnd, numeric_limits<int>::max(), ""); // 最优解
while (true)
{
if (vecOperate.size() <= 0)
break;
Point sPoint = vecOperate[0];
vecOperate.erase(vecOperate.begin());
if (sPoint.m_nPoint < nStart ||
sPoint.m_nValue >= sOptimalSolution.m_nValue ||
sPoint.m_szoper.find("+-") != string::npos ||
sPoint.m_szoper.find("-+") != string::npos)
continue;
if (sPoint.m_nPoint == nEnd)
{
sOptimalSolution = sPoint;
continue;
}
vecOperate.push_back( Point(sPoint.m_nPoint + 2, sPoint.m_nValue + nCost_Add, sPoint.m_szoper + string("+")) );
vecOperate.push_back( Point(sPoint.m_nPoint - 2, sPoint.m_nValue + nCost_Del, sPoint.m_szoper + string("-")) );
vecOperate.push_back( Point(sPoint.m_nPoint * 2, sPoint.m_nValue + nCost_Mul, sPoint.m_szoper + string("*")) );
}
cout << "最优消耗:" << sOptimalSolution.m_nValue << endl;
cout << "最优算法:" << sOptimalSolution.m_szoper << endl;
getchar();
getchar();
printf("Hello World!\n");
return 0;
} |
|