L2-4 哲哲打游戏 (25 分)(C/C++)

在这里插入图片描述
输入样例:

10 11
3 2 3 4
1 6
3 4 7 5
1 3
1 9
2 3 5
3 1 8 5
1 9
2 8 10
0
1 1
0 3
0 1
1 2
0 2
0 2
2 2
0 3
0 1
1 1
0 2

输出样例:

1
3
9
10

直接用二维数组会炸内存,所以用vector的一维数组当二维数组使用。
用vector a[N] 数组来存放每个剧情点对应操作能跳到哪个剧情点。
用int b[N]来存每个存档点对应的剧情点。
然后直接模拟即可。

#include<iostream>
#include<cstdio>
#include<iomanip>
#include<cstdlib>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<queue>
#include<stack>
#define llu unsigned long long
using namespace std;

vector<int> a[100010];
int b[100010];
int main()
{
	int n,m;
	cin >> n >> m;
	for(int i=1;i<=n;i++)
	{
		int t;
		cin >> t ;
		a[i].push_back(-1);
		for(int j=1;j<=t;j++)
		{
			int x;
			cin >> x;
			a[i].push_back(x); ;
		}
	}

	int t=1;//当前的剧情点,初始为1 
	for(int i=1;i<=m;i++)
	{
		int k,l;
		cin >> k >> l;
		if(k==0){
			t=a[t][l];
		}
		if(k==1){
			b[l]=t;
			cout << t << endl ; 
		}
		if(k==2){
			t=b[l];
		}
	}
	cout << t << endl ;
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值