Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
0ms水之。好不容易找到的规律(code)//发现一个数n,假如在树的倒数第floor层,则它的根节点为 //left = n - b[floor] + 1; //right = b[floor] + n - 1; //计算层数的话,就看这个数的因数里面的2的个数。 #include <iostream> using namespace std; int main(){ int t,n; scanf("%d",&t); long long b[33] = {1}; for(int i = 1 ; i <= 32 ; i ++ ){ b[i] = b[i - 1] << 1; b[i]; } while(t -- ){ scanf("%d",&n); int m = n; int floor = 0; while(!(m & 1)){//所在层数(倒数) m >>= 1; ++ floor; } int left = n - b[floor] + 1; int right = b[floor] + n - 1; if(!floor) printf("%d %d\n",n,n); else printf("%d %d\n",left,right); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator