AT_abc398_d [ABC398D] Bonfire 题解
题意:
给定三个数
分析:
如果直接按照题意移动烟雾,明显是会超时 + 超空间的。
分析样例,我们不难发现,从始至终,高桥与营火是相对静止的。因此,我们可以把烟雾对于营火和高桥的相对移动改为营火和高桥的移动,每次移动判断当前位置是否有烟雾就行了。
code:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second
#define fastrd ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pll pair<ll,ll>
map<pii,int>mp;
int n,a,b,x=0,y=0;
int main(){
fastrd
cin>>n>>a>>b;
for(int i=0;i<n;i++){
char c;
cin>>c;
mp[{x,y}]=1;//在当前位置放置烟雾
int xx=0,yy=0;
if(c=='N'){//由于是相对移动,所以所有移动方向是相反的
xx++;
}else if(c=='S'){
xx--;
}else if(c=='W'){
yy++;
}else{
yy--;
}
a+=xx;
x+=xx;
b+=yy;
y+=yy;
if(mp[{a,b}]){//如果移动到了有烟雾的格子,输出1
cout<<1;
}else{
cout<<0;
}
}
}