返回题解分享
讨论 / 题解分享/ 帖子详情

蛇形填数(结果填空) - 题解

#include <bits/stdc++.h>
using namespace std;
int a[300][300];
int main() {
int total=1,pox=0,poy=0,cnt=1;
a[0][0]=1;
for(int i=1;i<=50;i++){
if(i%2==1){
while(cnt<i){
a[--pox][++poy]=++total;
cnt++;
}
a[pox][++poy]=++total;
}else{
while(cnt<i){
a[++pox][--poy]=++total;
cnt++;
}
a[++pox][poy]=++total;
}
cnt=1;
}
cout<<a[19][19]<<" ";
}
仿照蛇形填数2的讲义,使用pos指针。两个while即为方向
0 回复 0 转发 0 喜欢 1 阅读
回复 (0)
默认 最新
暂无回复,快来抢沙发!