杭电acm1548 一直wrong answer

#include<iostream>usingnamespacestd;intb[201],A,B,n,d[2]={-1,1};structnode{intx,y,t;}... #include <iostream>
using namespace std;

int b[201],A,B,n,d[2]={-1,1};
struct node
{
int x,y,t;
}a[10000];
int fbs()
{
if(A==B)
return 0;
a[0].x=A; a[0].t=0; a[0].y=b[A];
b[A]=0;
int h=0,q=1;
while(h<q)
{
for(int i=0;i<=1;i++)
{
int xx=a[h].x+d[i]*a[h].y;
if(xx<1||xx>n)
continue;
if(b[xx]==0)
continue;
a[q].x=xx; a[q].y=b[xx]; a[q].t=a[h].t+1;
if(xx==B)
return a[q].t;
b[xx]=0;
q++;
}
h++;
}
return -1;
}

void main()
{
while(cin>>n,n)
{
cin>>A>>B;
for(int i=1;i<=n;i++)
cin>>b[i];
cout<<fbs()<<endl;
}
}

Problem Description
There is a strange lift.The lift can stop can at every floor as you want, and there is a number Ki(0 <= Ki <= N) on every floor.The lift have just two buttons: up and down.When you at floor i,if you press the button "UP" , you will go up Ki floor,i.e,you will go to the i+Ki th floor,as the same, if you press the button "DOWN" , you will go down Ki floor,i.e,you will go to the i-Ki th floor. Of course, the lift can't go up high than N,and can't go down lower than 1. For example, there is a buliding with 5 floors, and k1 = 3, k2 = 3,k3 = 1,k4 = 2, k5 = 5.Begining from the 1 st floor,you can press the button "UP", and you'll go up to the 4 th floor,and if you press the button "DOWN", the lift can't do it, because it can't go down to the -2 th floor,as you know ,the -2 th floor isn't exist.
Here comes the problem: when you is on floor A,and you want to go to floor B,how many times at least he havt to press the button "UP" or "DOWN"?

Input
The input consists of several test cases.,Each test case contains two lines.
The first line contains three integers N ,A,B( 1 <= N,A,B <= 200) which describe above,The second line consist N integers k1,k2,....kn.
A single 0 indicate the end of the input.

Output
For each case of the input output a interger, the least times you have to press the button when you on floor A,and you want to go to floor B.If you can't reach floor B,printf "-1".

Sample Input
5 1 5
3 3 1 2 5
0

Sample Output
3
展开
 我来答
百度网友1cf58ab
2012-08-18 · TA获得超过343个赞
知道小有建树答主
回答量:276
采纳率:50%
帮助的人:363万
展开全部
程序不符合题目要求。
Input
The input consists of several test cases.,
指输入包括多个测试用例。
Output
For each case of the input output a interger,
指每个测试用例输出一个数字。
这从它的输入样例上可以看出:
Sample Input
5 1 5
3 3 1 2 5
0 // 这个 0 就是输入的第二组数据
也就是说,一次输入全部测试用例,然后一次输出多个结果。
你的程序是输入一个测试用例输出一个结果,不合题意,结果肯定不对。
更多追问追答
追问
应该不是这个问题吧,我试了一下别人的AC代码,也是输入一个测试用例输出一个结果
追答
能否把别人的AC代码发上来,我比较一下。
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式