求调

P11228 [CSP-J 2024] 地图探险

muwan @ 2024-12-12 20:23:06

#include<bits/stdc++.h>
using namespace std;
const int N=1005;
int dir[4][2]={{1,0},{0,-1},{-1,0},{0,1}};
int n,m,k,x,y,d;
int ans;
int a[N][N];
int dfs(int x,int y,int d,int k,int ans)
{
    if(k==0)  return ans; 
        int nx=x+dir[d][0];
        int ny=y+dir[d][1];
        if(a[nx][ny]==1)  
        {
            a[nx][ny]=0;
            dfs(nx,ny,d,k-1,ans+1);
        }

        else dfs(x,y,(d+1)%4,k-1,ans);
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        memset(a,0,sizeof a);
        cin>>n>>m>>k;
        cin>>x>>y>>d;
        for(int i=1;i<=n;i++)
            for(int j=1;i<=m;j++)
            {
                char c;
                cin>>c;
                if(c!='x')  a[i][j]=1;
            }
            int qwq=dfs(x,y,d,k,0);
        cout<<qwq<<'\n';        
    }
    return 0;
 } 

by muwan @ 2024-12-12 20:23:23

没有输出


by Dio_The_World @ 2024-12-12 20:27:28

没判边界


by Dio_The_World @ 2024-12-12 20:28:25

@Dio_The_World第十三行


by muwan @ 2024-12-12 20:31:04

@Dio_The_World

memset  

边界直接设0了


by xk2013 @ 2024-12-14 16:58:36

@muwan 这不是深搜……是模拟。


by xk2013 @ 2024-12-14 16:59:59

@muwan 这是我的赛时代码:

#include <cstdio>
#include <cstring>

int T, n, m, k, x, y, d;
char map[1005][1005];
bool vis[1005][1005];

int main(void)
{
    freopen("explore.in", "r", stdin);
    freopen("explore.out", "w", stdout);

    scanf("%d", &T);

    while (T--)
    {
        int ans = 1;

        scanf("%d %d %d", &n, &m, &k);
        scanf("%d %d %d", &x, &y, &d);

        for (int i = 1; i <= n; i++)
        {
            scanf("%s", map[i] + 1);
        }

        vis[x][y] = true;

        for (int i = 1; i <= k; i++)
        {
            int tx, ty;

            switch (d)
            {
            case 0:
                tx = x;
                ty = y + 1;
                break;

            case 1:
                tx = x + 1;
                ty = y;
                break;

            case 2:
                tx = x;
                ty = y - 1;
                break;

            case 3:
                tx = x - 1;
                ty = y;
                break;
            }

            if (1 <= tx && tx <= n && 1 <= ty && ty <= m && map[tx][ty] == '.')
            {
                x = tx;
                y = ty;
            }
            else
            {
                d = (d + 1) % 4;
            }

            if (!vis[x][y])
            {
                vis[x][y] = true;
                ans++;
            }
        }

        memset(vis, 0, sizeof vis);
        printf("%d\n", ans);
    }

    return 0;
}

自己可以对照着改。


by F1reFly @ 2024-12-14 21:56:22

@xk2013 %%%虽然是模拟题但深搜也能过qwq


by xk2013 @ 2024-12-15 08:37:14

@F1reFly 只不过效率更加 slow


by F1reFly @ 2024-12-15 08:41:46

@xk2013是的,赛中大样例没输出,我的T2100分靠数据拿的


by xk2013 @ 2024-12-15 10:14:08

@F1reFly %%%


|