社区讨论
80分求条
P11228[CSP-J 2024] 地图探险参与者 2已保存回复 3
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 3 条
- 当前快照
- 1 份
- 快照标识符
- @m2q2a361
- 此快照首次捕获于
- 2024/10/26 19:12 去年
- 此快照最后确认于
- 2024/10/26 19:52 去年
CPP
#include<bits/stdc++.h>
using namespace std;
int n,m,k,d,x,y;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
string a[1005];
pair<int,int> hf(pair<int,int> l,set<pair<int,int> > &h)
{
pair<int,int> no={l.first+dx[d],l.second+dy[d]};
while(!((no.first>=0&&no.first<n&&no.second>=0&&no.second<m)&&(a[no.first][no.second]=='.')))
{
d=(d+1)%4;
no={l.first+dx[d],l.second+dy[d]};
k--;
}
if(k>0)
h.insert(no);
return no;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin>>t;
while(t--)
{
cin>>n>>m>>k;
cin>>x>>y>>d;
for(int i=0;i<n;i++)
cin>>a[i];
pair<int,int> p={x-1,y-1};
set<pair<int,int> > h;
h.insert(p);
while(k>0)
p=hf(p,h),k--;
cout<<h.size()<<'\n';
}
}
没想明白为啥用DFS做
回复
共 3 条回复,欢迎继续交流。
正在加载回复...