Codeforces Round 865 (Div. 2) 1816B - Grid Reconstruction Solution


 

Problem Link  :https://codeforces.com/problemset/problem/1816/B

Solution in C++:

  1. /// Author : AH_Tonmoy
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. int32_t main() {
  5. ios_base::sync_with_stdio(0);
  6. cin.tie(0);
  7. int t;
  8. cin >> t;
  9. while (t--) {
  10. int n , c ;
  11. cin >> n ;
  12. c = n ;
  13. int s1 = n*2 ;
  14. int s2 = n*2 - 1 ;
  15. int a[3][n*2] ;
  16. a[1][1] = n*2 ;
  17. a[2][n] = ( n*2 - 1);
  18. for ( int i = 2 ; i <= n ; i+=2 ){
  19. a[1][i] = i ;
  20. }
  21. for ( int i = 3 ; i <= n ; i+=2 ){
  22. s1 = s1 - 2 ;
  23. a[1][i] = s1 ;
  24. }
  25. for ( int i = 1 ; i < n ; i+= 2 ) {
  26. a[2][i] = i ;
  27. }
  28. for ( int i = 2 ; i < n ; i+=2 ){
  29. s2 = s2 - 2 ;
  30. a[2][i] = s2 ;
  31. }
  32. for ( int i = 1 ; i <= 2 ; i++ ){
  33. for ( int j = 1 ; j <= c ; j++) {
  34. cout << a[i][j] << " ";
  35. }
  36. cout << endl;
  37. }
  38. }
  39. return 0;
  40. }

No comments

Most View Post

Recent post

Codeforces Round 925 (Div. 3) 1931D. Divisible Pairs Solution

    Problem Link  :   https://codeforces.com/contest/1931/problem/D S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. ...

Powered by Blogger.