1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| using namespace std; #define ll long long ll a[1025][1025]; ll b[2][2]={{1,4},{2,3}}; const int maxn = 1e6+10; struct node { ll x, y; int cp; }arr[maxn]; int check(ll x,ll y,int num) { ll k = 1<<num; if(x<=k/2&&y<=k/2)return 1; else if(x>=k/2&&y<=k/2)return 3; else if(x<=k/2&&y>=k/2)return 2; else return 4; } ll solve(ll x,ll y,int k) { ll num = 1<<k; ll half = num/2; if(k==1)return b[--x][--y]; int area = check(x,y,k); if(area==1) { return solve(y,x,k-1); } else if(area==2) { y-=half; return half*half*3+solve(half-y+1,half-x+1,k-1); } else if(area==3) { return half*half*1+solve(x-half,y,k-1); } else if(area==4) { return half*half*2+solve(x-half,y-half,k-1); } } int cmp(node s,node t) { return s.cp<t.cp; } int main() { int n,k; scanf("%d %d",&n,&k); ll x,y; for(int i=0;i<n;i++) { scanf("%lld %lld",&arr[i].x,&arr[i].y); arr[i].cp=solve1(arr[i].x,arr[i].y,k); } sort(arr,arr+n,cmp); for(int i=0;i<n;i++) { printf("%lld %lld\n",arr[i].x,arr[i].y); } }
|