全部评论 2

  • 为了保证代码的可读性,请尽量使用markdown的代码块语法来包裹你的代码。

    语法:

    ```cpp
    在此粘贴你的代码
    ```

    效果:

    print("Hello World")
    

    2024-06-20 来自 浙江

    1
  • 我去牛逼

    
    #include <iostream>
    using namespace std;
    int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1}, ddx[4] = {0,1,0,-1}, ddy[4] = {-1,0,1,0}, ddx2[4]={-1,0,1,0}, ddy2[4]={0,-1,0,1}, ddx3[4]={1,0,-1,0}, ddy3[4]={0,-1,0,1}, ddx4[4]={0,-1,0,1}, ddy4[4]={1,0,-1,0}, ddx6[4] = {-1,0,1,0}, ddy6[4] = {0,1,0,-1}, ddx7[5] = {0,1,0,-1,0}, ddy7[5] = {-1,0,1,0,1};
    int a[20][20]={0}, vis[20][20]={0};
    int main() {
    	int n, x, y, f, dir = 0, num = 1, c = 0;
    	cin >> n >> x >> y >> f; 
        a[x][y] = vis[x][y] = num++;
        if(f == -1&& y!=0&&y!=n&&x!=n){
            for(int i = 0; i < 4; i++){
                dx[i] = ddx[i];
                dy[i] = ddy[i];
            }
       }
       else  if(f == -1&& y==n){
            for(int i = 0; i < 4; i++){
                dx[i] = ddx2[i];
                dy[i] = ddy2[i];
            }
       }
        else  if(f == -1&& x==n){
            for(int i = 0; i < 4; i++){
                dx[i] = ddx4[i];
                dy[i] = ddy4[i];
            }
       }
        else  if(f == -1&& y==1){
            for(int i = 0; i < 4; i++){
                dx[i] = ddx4[i];
                dy[i] = ddy4[i];
            }
       }
        else  if(f == 1&& y==n){
            for(int i = 0; i < 4; i++){
                dx[i] = ddx3[i];
                dy[i] = ddy3[i];
            }
       }
         else  if(f == 1&& x==n){
            for(int i = 0; i < 4; i++){
                dx[i] = ddx7[i];
                dy[i] = ddy7[i];
            }
       }     
        if(f == 1&& y==1){
            for(int i = 0; i < 4; i++){
                dx[i] = ddx6[i];
                dy[i] = ddy6[i];
            }
       }
        if(f == 1&& y==3&&x==n||y==2&&x==n&&f==1){
           
            	while(c <= 4){
            		int nx = x + ddx7[dir], ny = y + ddy7[dir];
            		if(vis[nx][ny] || nx < 1 || nx > n || ny < 1 || ny > n){
            			dir++;
            			c++;
            		}else{
            			c = 0;
            			a[nx][ny] = num++;
                        vis[nx][ny] = 1;
                        x = nx, y = ny;
                    }    
            		dir %= 5;
            	}
            	for(int i = 1; i <= n; i++){
            		for(int j = 1; j <= n; j++){
            			
    
    

    2024-06-20 来自 广东

    0
首页