[TIOJ]1994. 冰塊線
題目連結:http://tioj.infor.org/problems/1994
裸裸的遞迴下去,判斷朝向哪一邊即可~
我的code挺暴力的><
裸裸的遞迴下去,判斷朝向哪一邊即可~
我的code挺暴力的><
#include <iostream> #include <algorithm> #include <cmath> #include <bitset> #include <queue> #include <vector> #define lld long long #define PB push_back #define F first #define S second #define jizz cin.tie(0);ios_base::sync_with_stdio(0); #define endl '\n' using namespace std; typedef pair<int,int> Pair; int a[2050][2050]; void make(int x,int y,int l,int r,int sta){ if(r - l == 3){ if(sta == 1)a[x][y] = l,a[x+1][y] = l+1,a[x+1][y+1] = r-1,a[x][y+1] = r; if(sta == 2)a[x][y] = l,a[x+1][y] = r,a[x+1][y+1] = r-1,a[x][y+1] = l+1; if(sta == 3)a[x][y] = r-1,a[x+1][y] = r,a[x+1][y+1] = l,a[x][y+1] = l+1; if(sta == 4)a[x][y] = r-1,a[x+1][y] = l+1,a[x+1][y+1] = l,a[x][y+1] = r; return; } int t = (r-l+1)/4; int p = sqrt(r-l+1)/2; if(sta == 1){ make(x,y,l,l+t-1,2); make(x+p,y,l+t,l+2*t-1,1); make(x+p,y+p,r-2*t+1,r-t,1); make(x,y+p,r-t+1,r,4); } if(sta == 2){ make(x,y,l,l+t-1,1); make(x+p,y,r-t+1,r,3); make(x+p,y+p,r-2*t+1,r-t,2); make(x,y+p,l+t,l+2*t-1,2); } if(sta == 3){ make(x,y,r-t*2+1,r-t,3); make(x,y+p,l+t,l+2*t-1,3); make(x+p,y+p,l,l+t-1,4); make(x+p,y,r-t+1,r,2); } if(sta == 4){ make(x,y,r-t*2+1,r-t,4); make(x,y+p,r-t+1,r,1); make(x+p,y+p,l,l+t-1,3); make(x+p,y,l+t,l+2*t-1,4); } } int main(){jizz int n;cin >> n; if(!n)return puts("0"),0; make(1,1,1,(1 << n)*(1 << n),1); for(int i = 1; i <= (1 << n); i++) for(int j = 1; j <= (1 << n) ; j ++) cout << a[i][j]-1 << " \n"[j == (1 << n)]; return 0; }
留言
張貼留言