感觉这个应该是L2中最简单的一个,但是它放在第四个题而且题目和输入巨长,压根就没看。。看来每次还是要先看看所有的题目
思路
先根据输入的剧情信息建立一个动态锯齿数组,把每个剧情对应的分支存下来,再根据做出的选择,ans作为当前所在位置,初始为1,0选择,1存档,2读档
#include<iostream>
#include<vector>
using namespace std;
//book存储存档信息,为了方便,从1开始使用
int book[101] = { 0 };
int main()
{
int m, n;
cin >> m >> n;
vector<vector<int>> arr(n+1);
//将剧情信息存入
for (int i = 1; i <= m; i++)
{
int temp;
cin >> temp;
while (temp--)
{
int a;
cin >> a;
arr[i].push_back(a);
}
}
//初始为0
int ans = 1;
while (n--)
{
int a, b;
cin >> a>>b;
//选择分支,因为剧情分支从0开始存,所以b-1
if (a == 0)
{
ans = arr[ans][b-1];
}
//选择存档,并输出存档
if (a == 1)
{
book[b] = ans;
cout << ans << endl;
}
//读档,从b中取
if (a == 2)
{
ans = book[b];
}
}
//终点
cout << ans;
}