ACcode:
-
- #include<bits/stdc++.h>
- using namespace std;
- #define int long long
- const int N=70;
- int a[N][N],t,n,t1,t2;
- void solve() {
- cin>>n;
- vector<int>v;
- memset(a,0,sizeof a);
- t1=t2=0;
- for(int i=1;i<=n;i++)
- for(int j=1;j<=n;j++)
- cin>>a[i][j];
-
- for(int i=1;i<=n;i++){
- if(i%2!=0){
- for(int j=1;j<=n;j++){
- v.push_back(a[i][j]);
- }
- }
- else{
- for(int j=n;j>=1;j--){
- v.push_back(a[i][j]);
- }
- }
- }
- for(int i=0;i<n*n-1;i++){
- if(v[i]>v[i+1])t1++;
- else t2++;
- }
- if(t1<t2){
- for(int i=n*n-1;i>=0;i--){
- cout<<v[i]<<" ";
- }
- }
- else{
- for(int i=0;i<n*n;i++){
- cout<<v[i]<<" ";
- }
- }
- cout<<"\n";
- }
- signed main() {
- ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
- int t=1;
- cin>>t;
- while(t--) {
- solve();
- }
- return 0;
- }
-
-
-
over~