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

老是WA,贴代码求指教

Posted by qxzllcm at 2016-04-30 09:14:22 on Problem 3278
如题,老是WA,求大神指教
// POJ3278.cpp : 定义控制台应用程序的入口点。
//

//#include "stdafx.h"
#include <iostream>
#include <cmath>
#include <queue>
using namespace std;

int main()
{
	int n, k;
	int steps[200000];
	queue<int> q;
	while (cin >> n >> k)
	{
		memset(steps, 0, sizeof(steps));
		q.push(n);
		steps[n] = 0;
		while (1)
		{
			int base = q.front();
			q.pop();
			int dec = base - 1;
			if (dec >= 0 && dec <= 100000 && !steps[dec])
			{
				steps[dec] = steps[base] + 1;
				if (dec == k)
				{
					cout << steps[dec];
					break;
				}
				else
					q.push(dec);
			}
			int inc = base + 1;
			if (inc >= 0 && inc <= 100000 && !steps[inc])
			{
				steps[inc] = steps[base] + 1;
				if (inc == k)
				{
					cout << steps[inc];
					break;
				}
				else
					q.push(inc);
			}
			int dou = base + base;
			if (dou >= 0 && dou <= 100000 && !steps[dou])
			{
				steps[dou] = steps[base] + 1;
				if (dou == k)
				{
					cout << steps[dou];
					break;
				}
				else
					q.push(dou);
			}
		}
		while (!q.empty())
			q.pop();
	}
	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