正常的填数会暴毙,数据范围太大:$1 \leqslant n \leqslant 30,000,1 \leqslant i \leqslant n,1 \leqslant j \leqslant n$

int main(){	
int n,total=?,x=?,y=?,i,j;	//total表示每个格子中的数值	
cin>>n>>i>>j;	
total=a[++x][++y]=1;	
while (total<n*n)	//while (total<i*j)	
{	
while (a[x][y+1]==0&&y+1<=n) a[x][++y]=++total;//向右		
while (a[x+1][y]==0&&x+1<=n) a[++x][y]=++total;//向下		
while (a[x][y-1]==0&&y-1>=1) a[x][--y]=++total;//向左		
while (a[x-1][y]==0&&x-1>=1) a[--x][y]=++total;//向上
}	
cout<<a[i][j];	
return 0;
}

其实是个找规律😨

0 条评论

目前还没有评论...

信息

ID
24
时间
1000ms
内存
256MiB
难度
8
标签
递交数
139
已通过
20
上传者