Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
老是WA,贴代码求指教如题,老是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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator