专栏文章
题解:AT_abc398_d [ABC398D] Bonfire
AT_abc398_d题解参与者 1已保存评论 0
文章操作
快速查看文章及其快照的属性,并进行相关操作。
- 当前评论
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @mipu6wi5
- 此快照首次捕获于
- 2025/12/03 18:00 3 个月前
- 此快照最后确认于
- 2025/12/03 18:00 3 个月前
D - Bonfire
题目大意
给定在无限二维平面上的一个焰火位置 ,每个时刻烟雾会按照方向移动,若时刻 烟雾不在 ,则在 处重新生成烟雾。我们要判断在每个半时刻 时,给定坐标 是否存在烟雾。
解题思路
使用一个哈希集合保存已出现过烟雾的坐标。模拟每次风向移动,将当前位置偏移量与目标坐标 比较,通过哈希集合检查是否存在烟雾。
代码
CPPstruct P{
int r,c;
bool operator==(const P &o)const{
return r==o.r&&c==o.c;
}
};
struct Hash{
size_t operator()(const P &p)const{
return (size_t)p.r*13131u^(size_t)p.c;
}
};
int main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int n,r,c;
cin>>n>>r>>c;
string s;
cin>>s;
unordered_set<P,Hash> st;
st.insert({0,0});
int x=0,y=0;
string ans;
ans.resize(n);
for(int i=0;i<n;i++){
char d=s[i];
if(d=='N')x--;
if(d=='S')x++;
if(d=='W')y--;
if(d=='E')y++;
P t={x-r,y-c};
if(st.find(t)!=st.end())
ans[i]='1';
else
ans[i]='0';
P cur={x,y};
if(st.find(cur)==st.end())
st.insert(cur);
}
cout<<ans<<"\n";
return 0;
}
相关推荐
评论
共 0 条评论,欢迎与作者交流。
正在加载评论...