Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

我用visual c++ 2005可以编译通过,但是提交上去却得到compiler error

Posted by ildg at 2006-04-13 17:03:00 on Problem 1163
它这个系统用的是什么c++编译器?
3x,
我的代码如下:
#include <iostream>
#include <vector>
using namespace std;

int N;

class TrianglePosition
{
public:
	TrianglePosition(int x, int y, int v,vector<vector<TrianglePosition>>* triangle):_x(x),_y(y),_v(v),_s(-1),_triangle(triangle){}
	virtual ~TrianglePosition();
	int GetMaxSum();
private:
	vector<vector<TrianglePosition>>* _triangle;
	int _x;
	int _y;
	int _v;
	int _s;
	int max(int a, int b);
};

int TrianglePosition::GetMaxSum()
{
	if(_s>-1)
		return _s;
	else if(_x>=N-1)
	{
		_s=_v;
		return _s;
	}
	else
	{
		_s=_v+max(_triangle->at(_x+1).at(_y).GetMaxSum(),
			_triangle->at(_x+1).at(_y+1).GetMaxSum());
		return _s;
	}
}

int TrianglePosition::max(int a, int b)
{
	return a>b?a:b;
}

TrianglePosition::~TrianglePosition()
{
}

int main()
{
	cin>>N;
	vector<vector<TrianglePosition>> triangle;
	triangle.reserve(N);
	for(int i=0;i<N;i++)
	{
		vector<TrianglePosition> v;
		v.reserve(i+1);
		int tmp;
		for(int j=0;j<i+1;j++)
		{
			cin>>tmp;
			v.push_back(TrianglePosition(i,j,tmp,&triangle));
		}
		triangle.push_back(v);
	}
	int max_sum=triangle[0][0].GetMaxSum();
	cout<<max_sum<<endl;
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator