Advertisement
jakaria_hossain

codechef - even matrix

Jun 11th, 2020
989
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define fast()(ios_base::sync_with_stdio(0),cin.tie(NULL));
  5. int main()
  6. {
  7.     fast()
  8.     int t;
  9.     cin>>t;
  10.     while(t--)
  11.     {
  12.         int n,i,j,cnt=0,mx=1;
  13.         cin>>n;
  14.         for(i=1;i<=n;i++)
  15.         {
  16.             bool f;
  17.             if(i%2==1)
  18.                 {
  19.                     //cout<<++cnt<<" ";
  20.                     cnt=mx;
  21.                     mx+=n;
  22.                     f=true;
  23.                 }
  24.                 else
  25.                 {
  26.                     cnt=mx+n;
  27.                     mx+=n;
  28.                     f=false;
  29.                 }
  30.             for(j=1;j<=n;j++)
  31.             {
  32.                 if(f)
  33.                 {
  34.                     cout<<cnt++<<" ";
  35.  
  36.                 }
  37.                 else cout<<--cnt<<" ";
  38.  
  39.             }
  40.             cout<<endl;
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement