题解:P14736 [ICPC 2021 Seoul R] Find the House
思路
很板子的一道题。我记得有原的吧。
用一个变量存储当前的位置,然后每次去按照给定的方式去移动, 次后即为结果。注意区分 L 与 R。
代码
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n;
struct Node{
int d;char ch;
};
map<int,Node>mp;
signed main(){
cin>>n;
for(int i=1;i<=n;i++){
int t,te;char cc;cin>>t>>cc>>te;
mp[t]=Node{te,cc};
}
int now;cin>>now;
for(int i=1;i<=n;i++){
int dd=mp[now].d;
char cc=mp[now].ch;
if(cc=='L')now-=dd;
else now+=dd;
}
cout<<now;
return 0;
}