50分求调,又T又WA
查看原帖
50分求调,又T又WA
644697
van_Dijk楼主2023/8/26 13:28

代码如下:

#include <bits/stdc++.h>
using namespace std;

void FastIO() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
}

struct man {
	int side;
	string name;
} a[100001];

int main() {
	FastIO();
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
		cin >> a[i].side >> a[i].name;
	int s[100001], pos[100001];
	for (int i = 1; i <= m; i++)
		cin >> s[i] >> pos[i];
	string next = a[1].name;
	int nex = 1;
	for (int i = 1; i <= m; i++) {
		int p;
		for (int j = 1; j <= n; j++) {
			if (a[j].name == next) {
				p = j;
				break;
			}
		}
		if (s[i] == 0 && a[p].side == 0) {
			if (p - pos[i] <= 0) {
				nex = p + n - pos[i];
				next = a[nex].name;
			} else {
				nex = p - pos[i];
				next = a[nex].name;
			}
		}
		if (s[i] == 1 && a[p].side == 0) {
			if (p + pos[i] >= n) {
				nex = p + pos[i] - n;
				next = a[nex].name;
			} else {
				nex = p + pos[i];
				next = a[nex].name;
			}
		}
		if (s[i] == 1 && a[p].side == 1) {
			if (p - pos[i] <= 0) {
				nex = p + n - pos[i];
				next = a[nex].name;
			} else {
				nex = p - pos[i];
				next = a[nex].name;
			}
		}
		if (s[i] == 0 && a[p].side == 1) {
			if (p + pos[i] >= n) {
				nex = p + pos[i] - n;
				next = a[nex].name;
			} else {
				nex = p + pos[i];
				next = a[nex].name;
			}
		}
	}
	cout << next;
	return 0;
}
2023/8/26 13:28
加载中...