蒟蒻129行代码求助
查看原帖
蒟蒻129行代码求助
671420
panda791130楼主2022/8/7 21:49
#include <bits/stdc++.h>
using namespace std;
#define map jdasfhas
char map[15][15];
int cnt = 0;
int a, b;
int fx, fy, cx, cy;
bool go(int w, int face){
    if(face == 1){
        if(w == 1){
            if(map[fx][fy - 1] == '*'){
                return 0;
            } else{
                return 1;
            }
        } else{
            if(map[cx][cy - 1] == '*'){
                return 0;
            } else{
                return 1;
            }
        }
    } else if(face == 2){
        if(w == 1){
            if(map[fx + 1][fy] == '*'){
                return 0;
            } else{
                return 1;
            }
        } else{
            if(map[cx + 1][cy] == '*'){
                return 0;
            } else{
                return 1;
            }
        }
    } else if(face == 3){
        if(w == 1){
            if(map[fx][fy + 1] == '*'){
                return 0;
            } else{
                return 1;
            }
        } else{
            if(map[cx][cy + 1] == '*'){
                return 0;
            } else{
                return 1;
            }
        }
    } else if(face == 4){
        if(w == 1){
            if(map[fx - 1][fy] == '*'){
                return 0;
            } else{
                return 1;
            }
        } else{
            if(map[cx - 1][cy] == '*'){
                return 0;
            } else{
                return 1;
            }
        }
    }
}
int main()
{
    memset(map, '*', sizeof(map));
    for(int i = 1; i <= 10; i++){
        for(int j = 1; j <= 10; j++){
            cin >> map[i][j];
            if(map[i][j] == 'F'){
                fx = i;
                fy = j;
            } else if(map[i][j] == 'C'){
                cx = i;
                cy = j;
            }
        }
    }
    a = 1;
    b = 1;
    while((fx != cx) || (fy != cy)){
        if(go(1, a)){
            map[fx][fy] = '.';
            if(a == 1){
                fy--;
                map[fx][fy] = 'F';
            } else if(a == 2){
                fx++;
                map[fx][fy] = 'F';
            } else if(a == 3){
                fy++;
                map[fx][fy] = 'F';
            } else{
                fx--;
                map[fx][fy] = 'F';
            }
        } else{
            a++;
        }
        if(go(2, b)){
            map[cx][cy] = '.';
            if(b == 1){
                cy--;
                map[cx][cy] = 'C';
            } else if(b == 2){
                cx++;
                map[cx][cy] = 'C';
            } else if(b == 3){
                cy++;
                map[cx][cy] = 'C';
            } else{
                cx--;
                map[cx][cy] = 'C';
        	}
    	} else{
    		b++;
		}
    	cnt++;
    	if(cnt >= 1e9){
    		printf("0");
    		return 0;
		}
    }
    printf("%d", cnt);
    return 0;
}
2022/8/7 21:49
加载中...