跳到正文

个人记录

aa

Zhao_Yinghe约 2 分钟
原文
文章信息与版本

文章信息

发布
2025年5月8日
收录
2025年12月12日
更新
2026年11月17日
篇幅
约 2 分钟

版本

  1. v1当前
C++
#include <windows.h>
#include <bits/stdc++.h>
using namespace std;
#define int long long
int x,y,xx,yy;
bool a[111][111];
void draw(int n,int m){
	 
	a[x][y]=1;
	int q=rand()%(n+m)*5+1;
	aa:
	xx=x;
	yy=y;
	while(q--){
		int f=rand()%4+1,b=rand()%4+1;
		if(f==1){
			while(b--){
				xx++;
				if(xx>n||!xx||!yy||yy>m){
					goto aa;
				}
				a[xx][yy]=1;
			}
		}
		if(f==2){
			while(b--){
				xx--;
				if(xx>n||!xx||!yy||yy>m){
					goto aa;
				}
				a[xx][yy]=1;
			}
		}
		if(f==3){
			while(b--){
				yy++;
				if(xx>n||!xx||!yy||yy>m){
					goto aa;
				}
				a[xx][yy]=1;
			}
		}
		if(f==4){
			while(b--){
				yy--;
				if(xx>n||!xx||!yy||yy>m){
					goto aa;
				}
				a[xx][yy]=1;
			}
		}
	}
}
signed main(void){
	
	int n,m;
	cin>>n>>m;
	srand(time(0));
	x=rand()%n+1;
	y=rand()%m+1;
	xx=x;
	yy=y;
	draw(n,m);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(a[i][j]==0){
				cout<<"墙"; 
			}else if(i==x&&j==y){
				cout<<"我";
			}else if(i==xx&&j==yy){
				cout<<"终";
			}else{
				cout<<"  ";
			}
		}
		cout<<'\n';
	}
	return 0;
}
原文