社区讨论
求此题第一个点的数据,谢谢!
P1135奇怪的电梯参与者 2已保存回复 7
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 7 条
- 当前快照
- 1 份
- 快照标识符
- @lodgwl9r
- 此快照首次捕获于
- 2023/10/31 06:24 2 年前
- 此快照最后确认于
- 2023/11/06 21:39 2 年前
全都TLE。今天没下载次数了。唉。
CPP#include<iostream>
#include<queue>
#include<cstring>
using namespace std;
const int maxn = 205;
int n, a, b;
int delta[maxn], ans[maxn]; //delta[n] = d:第n层+-d层
int op[] = {1, -1};
queue<int> q;
int main(){
cin >> n >> a >> b;
memset(ans, -1, sizeof(ans));
ans[a] = 0;
for(int i = 1; i <= n; i++)
cin >> delta[i];
q.push(1);
while(!q.empty()){
int cur_f = q.front();
// cout << "current floor = " << cur_f << endl;
q.pop();
for(int i = 0; i < 2; i++){
int new_f = cur_f + op[i] * delta[cur_f];
if(new_f < 1 || new_f > n)
continue;
// cout << "new floor = " << new_f << " ";
ans[new_f] = ans[cur_f] + 1;
q.push(new_f);
}
}
cout << ans[b];
return 0;
}
回复
共 7 条回复,欢迎继续交流。
正在加载回复...