QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#705490 | #8981. Kangaroo Puzzle | alphaRaWaY | RE | 0ms | 0kb | C++14 | 1.8kb | 2024-11-02 23:40:35 | 2024-11-02 23:40:38 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define inc(i,a,b) for(int i(a);i<=b;i++)
#define dec(i,a,b) for(int i(a);i>=b;i--)
#define XisOK(x) x<=n&&x>=1
#define YisOK(y) y<=m&&y>=1
int n,m;
string ans("");
const int MaxN(25);
char ma[MaxN][MaxN];
char *dir="RUDLR";
map<char,int> id={{'U',1},{'D',2},{'L',3},{'R',4}};
int tx[5]={0,-1,1,0,0};
int ty[5]={0,0,0,-1,1};
bool vis[MaxN][MaxN];
int getVer(int i)
{
switch (i)
{
case 1:
return 2;
break;
case 2:
return 1;
break;
case 3:
return 4;
break;
case 4:
return 3;
break;
default:
break;
}
}
void dfs(int x,int y,int direction)
{
// cout<<x<<" "<<y<<endl;
inc(i,1,4)
{
if(XisOK(x+tx[i])&&YisOK(y+ty[i])&&ma[x+tx[i]][y+ty[i]]=='1'&&!vis[x+tx[i]][y+ty[i]])
{
vis[x+tx[i]][y+ty[i]]=true;
// cout<<ans<<endl;
ans+=dir[i];
dfs(x+tx[i],y+ty[i],i);
ans+=dir[getVer(i)];
}
}
}
void solve()
{
ans.clear();
cin>>n>>m;
inc(i,1,n)inc(j,1,m)vis[i][j]=false;
inc(i,1,n)
{
scanf("%s",ma[i]+1);
}
int rx(0),ry(0);
inc(i,1,n)
{
bool flag(false);
inc(j,1,m)
{
if(ma[i][j]=='1')
{
rx=i;ry=j,flag=true;
break;
}
}
if(flag)break;
}
vis[rx][ry]=true;
// inc(i,1,4)
// {
// cout<<dir[i]<<" "<<endl;
// cout<<tx[i]<<" "<<ty[i]<<endl;
// }
dfs(rx,ry,3);
cout<<ans<<endl;
}
signed main()
{
ios::sync_with_stdio(false);
int _;
// cin>>_;
_=1;
while(_--)solve();
system("pause");
}
详细
Test #1:
score: 0
Dangerous Syscalls
input:
4 4 1111 1001 1001 1110