Codeforces Round 865 (Div. 2) 1816B - Grid Reconstruction Solution
Problem Link :https://codeforces.com/problemset/problem/1816/B
Solution in C++:
- /// Author : AH_Tonmoy
- #include <bits/stdc++.h>
- using namespace std;
- int32_t main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- int t;
- cin >> t;
- while (t--) {
- int n , c ;
- cin >> n ;
- c = n ;
- int s1 = n*2 ;
- int s2 = n*2 - 1 ;
- int a[3][n*2] ;
- a[1][1] = n*2 ;
- a[2][n] = ( n*2 - 1);
- for ( int i = 2 ; i <= n ; i+=2 ){
- a[1][i] = i ;
- }
- for ( int i = 3 ; i <= n ; i+=2 ){
- s1 = s1 - 2 ;
- a[1][i] = s1 ;
- }
- for ( int i = 1 ; i < n ; i+= 2 ) {
- a[2][i] = i ;
- }
- for ( int i = 2 ; i < n ; i+=2 ){
- s2 = s2 - 2 ;
- a[2][i] = s2 ;
- }
- for ( int i = 1 ; i <= 2 ; i++ ){
- for ( int j = 1 ; j <= c ; j++) {
- cout << a[i][j] << " ";
- }
- cout << endl;
- }
- }
- return 0;
- }
No comments