UVa 712】的更多相关文章

https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=653 题意:给出满二叉树的叶子节点的值,给出路径并输出叶子节点的值 因为是满二叉树,所以就运用满二叉树的性质,往左走时L=2*L,往右走时就是L=2*L+1.这道题里第二行输入的东西完全没用,所以可以直接用个字符串来吃掉它.另外要注意的就是得把输出值先保存下来,最后一起输出. #includ…
二叉树? 怒水~~ 注意一下查询与x值的对应关系就好~ #include <iostream> #include <cstring> #include <cstdio> using namespace std; int main (){ ]; ],b[]; int n; int m; ; while (~scanf ("%d",&n)&&n){ ]; ;i<n;i++){ scanf ("%s",c)…
这个题根本不用建树,因为是完全二叉树,可以把这个想成二进制.对于根是二进制数的首位,之后依次类推.到最后的叶子节点就是从0到pow(2,n)-1. 关键在于在第一次输入的不是按照x1,x2,x3,x4这样的顺序输入的,那么我们就默认他的输入时按从二进制高位到地位.对于查询是按x1,x2,x3,x4这样的顺序.所以不能直接对应,需要一些小的操作来让查询的输入和二进制对的上. #include <iostream> #include <cstring> #include <str…
题意: 给定一颗n层的二叉树的叶子, 然后给定每层走的方向, 0代表左边, 1代表右边, 求到达的是那一个叶子. 每层有一个编号, 然后n层的编号是打乱的, 但是给的顺序是从1到n. 分析: 先用一个f数组把一开始打乱的顺序存起来,  将他变为有序, 然后之后读取走的方法, 把他先转化为给定的层次顺序, 然后再转换为给定的二进制序号, 然后转化为十进制就是知道是几个叶子了. #include <bits/stdc++.h> using namespace std; int n, m; ], f…
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] dfs模拟一下就好. 先预处理一个dfs. 搞出来x叶子节点它的值是什么 [代码] /* 1.Shoud it use long long ? 2.Have you ever test several sample(at least therr) yourself? 3.Can you promise that the solution is right? At least,the main ideal 4.use the pu…
题意:0往左走,1往右走,已知所有叶子的值,每个查询都是根结点到叶子结点的路径,路径的每一个点分别对应着x1,x2,x3……但是实际上的S树的路径可能并非是x1,x2,x3…… 分析:先存路径变量的顺序,来控制最后访问的顺序. #pragma comment(linker, "/STACK:102400000, 102400000") #include<cstdio> #include<cstring> #include<cstdlib> #incl…
  A Strange Tree (S-tree) over the variable set Xn = {x1,x2,...,xn} is a binary tree representing a Boolean function f : {0,1}n → {0,1}. Each path of the S-tree begins at the root node and consists of n + 1 nodes. Each of the S-tree's nodes has a dep…
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 迭代加深搜索. 每次抽动操作最多只会让中间那一块的区域离目标的"距离"减少1. 以这个作为剪枝. 枚举最大深度. 就能过了. [代码] #include <iostream> #include <cstdlib> #include <cstdio> #include <algorithm> #include <vector> using namespace s…
uva 10718  Bit Mask  (位运算) Problem A Bit Mask Time Limit 1 Second In bit-wise expression, mask is a common term. You can get a certain bit-pattern using mask. For example, if you want to make first 4 bits of a 32-bit number zero, you can use 0xFFFFFF…
题意:给出几个圆的半径,贴着底下排放在一个长方形里面,求出如何摆放能使长方形底下长度最短. 由于球的个数不会超过8, 所以用全排列一个一个计算底下的长度,然后记录最短就行了. 全排列用next_permutation函数,计算长度时坐标模拟着摆放就行了. 摆放时折腾了不久,一开始一个一个把圆放到最左端,然后和前面摆好的圆比较检查是否会出现两个圆重叠,是的话就把当前圆向右移动到相切的位置.然后判断宽度. 结果发现过不了几个例子,检查了好久,终于发现问题出在初始位置上,如果出现一个特别小的圆放到最左…