Created
April 11, 2020 15:09
-
-
Save asSqr/ea833ffa54c5d66e40caaa1d0ddadd71 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
#include <cstdlib> | |
#include <cassert> | |
#include <algorithm> | |
#include <functional> | |
#include <iostream> | |
#include <map> | |
#include <numeric> | |
#include <queue> | |
#include <set> | |
#include <stack> | |
#include <string> | |
#include <vector> | |
#define repi(i,a,b) for(int i=(a);i<(b);++i) | |
#define rep(i,a) repi(i,0,a) | |
#define all(a) (a).begin(), (a).end() | |
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } | |
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } | |
using ll = long long; | |
ll T; | |
bool used[50]; | |
void clear() | |
{ | |
rep( b, 50 ) | |
used[b] = false; | |
return; | |
} | |
ll popcount( ll x ) | |
{ | |
ll ret = 0, cnt = 0; | |
while( x > 0 ) | |
{ | |
if( x&1 ) | |
++ret, used[cnt] = true; | |
x >>= 1; | |
++cnt; | |
} | |
return ret; | |
} | |
int main() | |
{ | |
std::cin >> T; | |
rep( t, T ) | |
{ | |
ll N; | |
std::cin >> N; | |
ll ans; | |
ll two = 1, bit = 0; | |
--N; | |
while( two < N ) | |
two <<= 1, ++bit; | |
--bit; | |
rep( r, bit+2 ) | |
{ | |
clear(); | |
if( r == popcount(two-N+r) ) | |
{ | |
break; | |
} | |
} | |
ll r = 1, c = 1; | |
rep( rc, bit ) | |
{ | |
if( !used[rc] ) | |
{ | |
if( c == r ) | |
{ | |
std::cout << r << ' ' << c << std::endl; | |
while( c > 1 ) | |
{ | |
--c; | |
std::cout << r << ' ' << c << std::endl; | |
} | |
} | |
else | |
{ | |
std::cout << r << ' ' << c << std::endl; | |
while( c < r ) | |
{ | |
++c; | |
std::cout << r << ' ' << c << std::endl; | |
} | |
} | |
} | |
else | |
{ | |
std::cout << r << ' ' << c << std::endl; | |
} | |
++r; | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment