楼主: 帛裂七弦

[【其他】] 最省钱种树方法计算器(第三版,修正之前错误)

[复制链接]

1734

帖子

2347

威望

2424

金豆

LV.7

Rank: 7Rank: 7Rank: 7

积分
3409
发表于 2010-5-6 18:05:58 | 显示全部楼层
我用的是VC++编译的,
回复 支持 反对

使用道具 举报

132

帖子

141

威望

0

金豆

LV.2

Rank: 2

积分
141
QQ
发表于 2010-5-6 18:06:11 | 显示全部楼层
一个小问题被搞的那么复杂我擦!!!上过高中的人 不会像你这么累!我们都是老师教的~你们是靠摸索的哈哈!一看楼主没上过高中
风雨剑侠梦 发表于 2010-5-6 16:57


无知者无畏

举个例子
从27种到390
+2,-2要10W,*2要20W
您准备花多少钱?

可别偷偷别用俺的计算器哦~
死生在手 变化由心 地步能埋 天不能煞
回复 支持 反对

使用道具 举报

132

帖子

141

威望

0

金豆

LV.2

Rank: 2

积分
141
QQ
发表于 2010-5-6 18:07:35 | 显示全部楼层
代码进入编译器,怎么错误这么多,,,
disable 发表于 2010-5-6 18:04


呵呵,开始用2005写的,改到vc6要有些改动的
死生在手 变化由心 地步能埋 天不能煞
回复 支持 反对

使用道具 举报

1734

帖子

2347

威望

2424

金豆

LV.7

Rank: 7Rank: 7Rank: 7

积分
3409
发表于 2010-5-6 18:09:31 | 显示全部楼层
怎么连 主函数 都找不到,你怎么编译成功的,,,
回复 支持 反对

使用道具 举报

132

帖子

141

威望

0

金豆

LV.2

Rank: 2

积分
141
QQ
发表于 2010-5-6 18:14:36 | 显示全部楼层
怎么连 主函数 都找不到,你怎么编译成功的,,,
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;
}
死生在手 变化由心 地步能埋 天不能煞
回复 支持 反对

使用道具 举报

1734

帖子

2347

威望

2424

金豆

LV.7

Rank: 7Rank: 7Rank: 7

积分
3409
发表于 2010-5-6 18:16:05 | 显示全部楼层
用C的编译器写的吧,一看结构体就知道了
我用的是VC++,你告诉我下作哪些修改
连主函数都找不到,怎么编译成功嘛~~~~~~~~~~~~~~
回复 支持 反对

使用道具 举报

1734

帖子

2347

威望

2424

金豆

LV.7

Rank: 7Rank: 7Rank: 7

积分
3409
发表于 2010-5-6 18:18:45 | 显示全部楼层
这个头文件找不到,就差它一个错误。。。
22222.jpg
回复 支持 反对

使用道具 举报

132

帖子

141

威望

0

金豆

LV.2

Rank: 2

积分
141
QQ
发表于 2010-5-6 18:20:48 | 显示全部楼层
没有.h
#include <vector>
死生在手 变化由心 地步能埋 天不能煞
回复 支持 反对

使用道具 举报

1734

帖子

2347

威望

2424

金豆

LV.7

Rank: 7Rank: 7Rank: 7

积分
3409
发表于 2010-5-6 18:22:46 | 显示全部楼层
没有.h
#include
帛裂七弦 发表于 2010-5-6 18:20
没有它直接编译不成功
回复 支持 反对

使用道具 举报

1734

帖子

2347

威望

2424

金豆

LV.7

Rank: 7Rank: 7Rank: 7

积分
3409
发表于 2010-5-6 18:23:50 | 显示全部楼层
没有.h
#include
帛裂七弦 发表于 2010-5-6 18:20
你看,直接不行
33333.jpg
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver| 剑侠情缘网络版  

Powered by Discuz! X3.1

Copyright © 2014 Kingsoft Corporation.All rights reserved. 金山软件 版权所有

快速回复 返回顶部 返回列表
论坛导航