QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#705490#8981. Kangaroo PuzzlealphaRaWaYRE 0ms0kbC++141.8kb2024-11-02 23:40:352024-11-02 23:40:38

Judging History

你现在查看的是最新测评结果

  • [2024-11-05 18:07:55]
  • hack成功,自动添加数据
  • (/hack/1130)
  • [2024-11-02 23:40:38]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-11-02 23:40:35]
  • 提交

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

output:


result: