Uva 679 Dropping Balls
2014-07-18 10:27
423 查看
Dropping Balls |
For example, Fig. 1 represents a fully binary tree of maximum depth 4 with
the node numbers 1, 2, 3, ..., 15. Since all of the flags are initially set to
be false, the first ball being dropped will switch flag's values at node
1, node 2, and node 4 before it finally stops at position 8. The second ball
being dropped will switch flag's values at node 1, node 3, and node 6, and
stop at position 12. Obviously, the third ball being dropped will switch
flag's values at node 1, node 2, and node 5 before it stops at position 10.
#include<iostream> #include<string.h> #include<stdio.h> #include<ctype.h> #include<algorithm> #include<stack> #include<queue> #include<set> #include<math.h> #include<vector> #include<map> #include<deque> #include<list> using namespace std; const int maxd = 20; int s[1<<maxd];//1^20,<<是二进制向左偏移的意思 int main() { int D,I; while(scanf("%d%d",&D,&I)==2) { memset(s,0,sizeof(s)); int k,n=(1<<D)-1; for(int i=0;i<I;i++) { k=1; while(k<=n) { s[k]=!s[k]; k=s[k]?k*2:k*2+1;//二叉树 } } printf("%d\n",k/2); } return 0; }
View Code
相关文章推荐
- Dropping Balls - UVa 679 简单二叉树问题
- UVA 679 Dropping Balls 【模拟+数学规律】
- UVa 679 - Dropping Balls
- Uva679 Dropping Balls【二叉树技巧】【例题6-6】
- UVa 679 - Dropping Balls
- UVA 679 Dropping Balls (二叉树的编号)
- UVA 679 Dropping Balls 【二叉树】
- UVA-679 Dropping Balls
- UVA - 679 Dropping Balls 二叉树找规律
- UVa 679 Dropping Balls
- UVa 679 - Dropping Balls
- UVa 679 Dropping Balls
- UVa 679 - Dropping Balls
- 例题 6-6 小球下落(Dropping Balls) UVa 679 二叉树规律
- UVA 679 - Dropping Balls
- UVA - 679 Dropping Balls
- Uva - 679 - Dropping Balls
- uva679 Dropping Balls
- UVa-679 Dropping Balls
- UVA_679: Dropping Balls