jiangjiang 题目问答 · 2024/4/4
60分,想知道问题在哪
```cpp #include<iostream> #include<vector> using namespace std; int main() { int m, n; cin >> m >> n; vector<vector<int>> nums(m+1, vector<int>(n+1, 0)); int top = 1, bottom = m, left = 1, right = n; for (int i = 1;i<=m*n;) { for (int j = top; j <= bottom; ++j) { nums[j][right] = i; i++; } right--; for (int j = right; j >= left; --j) { nums[bottom][j] = i; i++; } bottom--; for (int j = bottom; j >= top; j--) { nums[j][left] = i; i++; } left++; for (int j = left; j <= right; ++j) { nums[top][j] = i; i++; } top++; } for(int i = 1; i <= m; ++i) { for (int j = 1; j <= n; ++j) { printf("%5d", nums[i][j]); } cout << endl; } return 0; } ```
查看全文
2 0 0 111
Argn 题目问答 · 2024/4/9
再发一遍代码
```cpp #include<bits/stdc++.h> using namespace std; int a[105][105]={0}; int main(){ // ios::sync_with_stdio(0); // cin.tie(0); // cout.tie(0); int n,m; scanf("%d %d",&n,&m); memset(a,0,sizeof(a)); int tot=1,x=0,y=m-1; a[x][y]=1; while(tot<n*m){ while(x+1<n&&!a[x+1][y]) a[++x][y]=++tot; while(y-1>=0&&!a[x][y-1]) a[x][--y]=++tot; while(x-1>=0&&!a[x-1][y]) a[--x][y]=++tot; while(y+1<n&&!a[x][y+1]) a[x][++y]=++tot; } for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ printf("%5d",a[i][j]); } printf("\n"); } return 0; } ```
查看全文
1 0 0 46
CyssAdo39 题目问答 · 2024/4/7
一分没拿,但是自己跑的结果都是符合要求的,想知道问题出在哪,谢谢
```cpp #include using namespace std; int main() { ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); int i,j,n=1,a[100][100]; cin >>i>>j; int x=0,y=j-1; a[x][y]=1; while(1) { if(n==i*j) break; while(1) { if(n==i*j) break; if(x<i-1&&a[x+1][y]==0) { n++; x++; a[x][y]=n; } else break; if(n==i*j) break; } while(1) { if(n==i*j) break; if(y>0&&a[x][y-1]==0) { n++; y--; a[x][y]=n; } else break; if(n==i*j) break; } while(1) { if(n==i*j) break; if(x>0&&a[x-1][y]==0) { n++; x--; a[x][y]=n; } else break; if(n==i*j) break; } while(1) { if(n==i*j) break; if(y<j-1&&a[x][y+1]==0) { n++; y++; a[x][y]=n; } else break; if(n==i*j) break; } if(n==i*j) break; } for(int k=0;k<i;k++) { for(int l=0;l<j;l++) { printf("%5d",a[k][l]); } cout << endl; } return 0; } ```
查看全文
0 0 0 136
Argn 题目问答 · 2024/4/9
想问一下,我的代码为什么会超时,感觉和老师写的一样啊
```cpp #include<bits/stdc++.h> using namespace std; int a[105][105]={0}; int main(){ // ios::sync_with_stdio(0); // cin.tie(0); // cout.tie(0); int n,m; scanf("%d %d",&n,&m); memset(a,0,sizeof(a)); int tot=1,x=0,y=m-1; a[x][y]=1; while(tot<n*m){ while(x+1<n&&!a[x+1][y]) a[++x][y]=++tot; while(y-1>=0&&!a[x][y-1]) a[x][--y]=++tot; while(x-1>=0&&!a[x-1][y]) a[--x][y]=++tot; while(y+1<n&&!a[x][y+1]) a[x][++y]=++tot; } for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ printf("%5d",a[i][j]); } printf("\n"); } return 0; } ```
查看全文
0 0 0 79