求调
  • 板块灌水区
  • 楼主CJR_Rain
  • 当前回复8
  • 已保存回复8
  • 发布时间2025/1/9 20:51
  • 上次更新2025/1/10 12:50:58
查看原帖
求调
1382345
CJR_Rain楼主2025/1/9 20:51
#include <iostream>
#include <cstring>

using namespace std;

string map[1005];
bool bef[1005][1005];

int main() {
    
    int T;
    scanf("%d",&T);
    
    while(T-- != 0) {
        
        memset(bef, false, sizeof(bef));
        
        int n,m,k,x,y,d,ans = 0;
        scanf("%d%d%d%d%d%d",&n,&m,&k,&x,&y,&d);
        
        --x;
        --y;
        
        cin.tie(nullptr) -> ios::sync_with_stdio(false);
        
        for(int i = 0; i < n; ++i) {
            
            cin >> map[i];
        }
        
        cin.tie(0) -> ios::sync_with_stdio(true);
        
        while(k-- != 0) {
            
            if(bef[x][y] == false) {
                
                ++ans;
            }
            
            bef[x][y] = true;
            
            if(d == 0) {
                
                if(y < m - 1 && map[x][y + 1] == '.') {
                    
                    ++y;
                }
                
                else {
                    
                    d = (d + 1) & 3;
                }
            }
            
            else if(d == 1) {
                
                if(x < n - 1 && map[x + 1][y] == '.') {
                    
                    ++x;
                }
                
                else {
                    
                    d = (d + 1) & 3;
                }
            }
            
            else if(d == 2) {
                
                if(y > 0 && map[x][y - 1] == '.') {
                    
                    --y;
                }
                
                else {
                    
                    d = (d + 1) & 3;
                }
            }
            
            else {
                
                if(x > 0 && map[x - 1][y] == '.') {
                    
                    --x;
                }
                
                else {
                    
                    d = (d + 1) & 3;
                }
            }
        }
        
        if(bef[x][y] == false) {
            
            ++ans;
        }
        
        printf("%d\n",ans);
    }
    
    return 0;
}

for(int i = 0; i < n; ++i) {
            
    cin >> map[i];
}

这一段代码运行时不知道问什么输入会出现问题(好像是i10i≤10时?)

2025/1/9 20:51
加载中...