UVa 712/POJ 1105/ZOJ 1150 S-Trees(用数组模拟二叉树)

com.sap.aii.af.service.cpa.CPAObjectNotFoundException: Couldn‘t retrieve inbound binding 错误消息:错误截图:该错误通常表示在集成配置中,未找到与特定消息匹配的入站绑定(Inbound Binding)。具体而言,错误消息中的 P/S/A(Party/Service/Action)值未在配置中找到对应的入站绑定。 阅读详情

712 - S-Trees

Time limit: 3.000 seconds

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=104&page=show_problem&problem=653

http://poj.org/problem?id=1105

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1150

A Strange Tree (S-tree) over the variable set $X_n = \{x_1, x_2, \dots, x_n\}$ is a binary tree representing a Boolean function $f: \{0, 1\}^n \rightarrow \{ 0, 1\}$. Each path of the S-tree begins at theroot node and consists of n+1 nodes. Each of the S-tree's nodes has a depth, which is the amount of nodes between itself and the root (so the root has depth 0). The nodes with depth less than n are called non-terminal nodes. All non-terminal nodes have two children: the right child and the left child. Each non-terminal node is marked with some variable xi from the variable set Xn. All non-terminal nodes with the same depth are marked with the same variable, and non-terminal nodes with different depth are marked with different variables. So, there is a unique variable xi1 corresponding to the root, a unique variable xi2 corresponding to the nodes with depth 1, and so on. The sequence of the variables $x_{i_1}, x_{i_2}, \dots, x_{i_n}$ is called the variable ordering. The nodes having depth n are called terminal nodes. They have no children and are marked with either 0 or 1. Note that the variable ordering and the distribution of 0's and 1's on terminal nodes are sufficient to completely describe an S-tree.

As stated earlier, each S-tree represents a Boolean function f. If you have an S-tree and values for the variables $x_1, x_2, \dots, x_n$, then it is quite simple to find out what$f(x_1, x_2, \dots, x_n)$ is: start with the root. Now repeat the following: if the node you are at is labelled with a variable xi, then depending on whether the value of the variable is 1 or 0, you go its right or left child, respectively. Once you reach a terminal node, its label gives the value of the function.

Figure 1: S-trees for the function $x_1 \wedge (x_2 \vee x_3)$

On the picture, two S-trees representing the same Boolean function,$f(x_1, x_2, x_3) = x_1 \wedge (x_2 \vee x_3)$, are shown. For the left tree, the variable ordering is x1, x2,x3, and for the right tree it is x3, x1, x2.

The values of the variables $x_1, x_2, \dots, x_n$, are given as a Variable Values Assignment(VVA) 

\begin{displaymath}(x_1 = b_1, x_2 = b_2, \dots, x_n = b_n)\end{displaymath}

with  $b_1, b_2, \dots, b_n \in \{0,1\}$ . For instance, (  x 1  = 1,  x 2  = 1  x 3  = 0) would be a valid VVA form  = 3, resulting for the sample function above in the value  $f(1, 1, 0) = 1 \wedge (1 \vee 0) = 1$ . The corresponding paths are shown bold in the picture.

Your task is to write a program which takes an S-tree and some VVAs and computes$f(x_1, x_2, \dots, x_n)$ as described above.

Input 

The input file contains the description of several S-trees with associated VVAs which you have to process. Each description begins with a line containing a single integer n ,  $1 \le n \le 7$ , the depth of the S-tree. This is followed by a line describing the variable ordering of the S-tree. The format of that line is  x i 1   x i 2  ... x i n . (There will be exactly  n  different space-separated strings). So, for  n  = 3 and the variable ordering  x 3 ,  x 1 ,  x 2 , this line would look as follows:

x3 x1 x2

In the next line the distribution of 0's and 1's over the terminal nodes is given. There will be exactly 2n characters (each of which can be 0 or 1), followed by the new-line character. The characters are given in the order in which they appear in the S-tree, the first character corresponds to the leftmost terminal node of the S-tree, the last one to its rightmost terminal node.

The next line contains a single integer m, the number of VVAs, followed by m lines describing them. Each of the m lines contains exactly n characters (each of which can be 0 or 1), followed by a new-line character. Regardless of the variable ordering of the S-tree, the first character always describes the value of x1, the second character describes the value of x2, and so on. So, the line

110

corresponds to the VVA ( x1 = 1, x2 = 1, x3 = 0).

The input is terminated by a test case starting with n = 0. This test case should not be processed.

Output 

For each S-tree, output the line `` S-Tree # j : ", where  j  is the number of the S-tree. Then print a line that contains the value of  $f(x_1, x_2, \dots, x_n)$  for each of the given  m VVAs, where  f  is the function defined by the S-tree.

Output a blank line after each test case.

Sample Input 

3
x1 x2 x3
00000111
4
000
010
111
110
3
x3 x1 x2
00010011
4
000
010
111
110
0

Sample Output 

S-Tree #1:
0011

S-Tree #2:
0011

英语阅读题=v=:

注意:Depending on whether the value of the variable is 1 or 0, you go its right or left child

变量为1,去右孩子;变量为0,去左孩子。


思路:

建一个二叉树或用数组也行。

(由于数据范围较小:n<=7,这里用数组要好些)


完整代码:(太慢了,没到0ms)

/*UVaOJ: 0.016s*/
/*POJ: 16ms,144KB*/
/*ZOJ: 0ms,180KB*/

#include<cstdio>
#include<cstring>
using namespace std;
int serial[7];
char ch[1<<7],temp[7];

int main()
{
	int cas = 1;
	while (true)
	{
		int n, t, size;
		scanf("%d", &n);
		if (!n)
			break;
		getchar();//别忘了读去'\n'

		//读取x3 x1 x2这样的
		getchar();
		for (int i = 0; i < n - 1; i++)
		{
			scanf("%d", &serial[i]);
			--serial[i];//这里要减一
			getchar();
			getchar();
		}
		scanf("%d", &serial[n - 1]);
		--serial[n - 1];
		getchar();//别忘了读去'\n'

		//读取00010011
		size = 1 << n;
		for (int i = 0; i < size; i++)
			ch[i] = getchar();

		printf("S-Tree #%d:\n", cas++);
		scanf("%d", &t);
		getchar();//别忘了读去'\n'
		while (t--)
		{
			for (int i = 0; i < n; i++)
				temp[i] = getchar();
			getchar();//别忘了读去'\n'
			int l = 0, r = size, m = size >> 1;
			for (int i = 0; i < n; i++)
			{
				if (temp[serial[i]] == '0')
					r = m;
				else
					l = m;
				m = (l + r) >> 1;
			}
			printf("%c", ch[l]);
		}
		printf("\n\n");
	}
	return 0;
}

Source


第6章: MMU Notifier在KVM虚拟化中的应用 本文分析了KVM如何利用MMU Notifier机制维护客户机与宿主机地址映射一致性。KVM采用三层地址空间转换架构(GVA→GPA→HPA),通过硬件辅助虚拟化(EPT/NPT)实现高效转换。重点探讨了KVM MMU Notifier回调实现,包括invalidate_range_start/end等核心函数,以及HVA范围处理流程。当宿主机内存变化时,KVM通过注册的notifier回调及时更新映射关系,确保虚拟化环境的内存一致性。文章详细解析了相关数据结构和关键代码实现,揭示了KVM内存管理的核心机制 阅读详情

相关推荐

从零到一:PrimeTime静态时序分析入门指南

本文详细介绍了PrimeTime静态时序分析(STA)的入门指南,从基础概念到实际应用全面覆盖。内容包括时序路径分类、PrimeTime环境搭建、时序约束设置与验证、时序分析与报告解读等核心内容,帮助工程师快速掌握STA技术,解决数字芯片设计中的时序收敛问题。

weixin_28730131的博客 268

[UVa 712] S 树(S-Trees)

Judge:https://vjudge.net/problem/UVA-712 题意:给定一棵满二叉树的叶节点的值,求每个查询到达的叶子的值。查询从根节点开始,0表示向左走,1表示向右走。

StarlitNight的博客 672

Ghidra逆向分析实战:从安装JDK到解析STM32的bin文件(附SVD插件配置)

本文详细介绍了使用Ghidra进行STM32固件逆向分析的完整流程,从JDK安装配置到SVD插件的应用。通过实战案例展示如何解析bin文件、恢复符号信息以及利用SVD插件识别外设寄存器,帮助开发者高效完成嵌入式设备的逆向工程任务。

weixin_29309475的博客 643

UVA 712 S-Trees 解题报告

AC之后看了看网上的代码,我人麻了 o_O。 先上我的代码: #include <iostream> // Uva 712 #include <map> using namespace std; int nowdepth = 1; // 遍历二叉树时 记录每时每刻走到的树的深度 int pace = -1; // 输入01串,需要记录给下一片叶子赋为何值,pace为01串的下标 int init = 1; typedef struct Tre

weixin_52450397的博客 266

英飞凌TC3xx DSADC旋变软解码实战:从示波器波形到VX1000数据,手把手教你避坑

本文详细介绍了英飞凌TC3xx系列微控制器的DSADC模块在电机旋变软解码中的实战应用。从示波器波形分析到VX1000数据采集,提供了一套完整的调试方法论,帮助工程师快速定位和解决常见问题,提升解码精度和系统性能。

weixin_30598225的博客 517

[WeChatMsg]导出csv格式微信聊天记录的手把手教程

手把手教大家如何导出自己的聊天记录得到csv文件,即使是电脑小白也可以轻松学会o(* ̄▽ ̄*)ブ

weixin_51094633的博客 1万+

UVaOJ712---S-Trees

712 - S-Trees Time limit: 3.000 seconds A Strange Tree (S-tree) over the variable set  is a binary tree representing a Boolean function . Each path of the S-tree begins at the root node and co

c随遇er安的专栏 683

计算机毕业设计springboot基于微信平台的二次元手办商场小程序【附源码】

选题背景: 随着二次元文化的兴起和普及,越来越多的人开始对二次元角色产生了浓厚的兴趣和喜爱。手办作为二次元文化的重要载体之一,成为了许多二次元爱好者收藏和展示的对象。然而,在传统的线下手办商场中,消费者往往面临着时间、空间和选择的限制。因此,基于微信平台的二次元手办商场小程序应运而生。 选题意义: 首先,基于微信平台的二次元手办商场小程序能够打破地域限制,使得用户可以随时随地通过手机进行购物。无论是在家中、上班途中还是旅行中,用户都能够方便地浏览和购买自己喜欢的手办,极大地提高了购物的便利性和灵活性。

拉期程序 451

uva712解题报告

没有发现x1,x2是干什么用的,不过我发现直接把二进制转成十进制就可以ac掉了 AC代码 Time 0ms #include #include #include using namespace std; const int maxn=256+10; char buf[maxn]; int leap[maxn],n,q; void build() { int len=strlen(

董成荣的博客 890

056:vue+openlayers 风场快速移动效果(图文代码)

本示例的目的是介绍演示如何在vue+openlayers中使用wind插件来实现风场快速移动的效果。

大剑师兰特的GIS世界 1580

单反相机物镜设计[DG-10]

REAR(要打在像面,操作数要找像面对应位置15):以透镜单位表示的真实光线径向坐标,波长由Wave定义,参见“Hx、Hy、Px和Py”。最小玻璃厚度最小不能小于semi-dia的1/10,要根据layout看有没有过厚过薄,反复调节。PROD:两个操作数的乘积(操作#1 X操作#2)。3x4就是57.3x0.41=23.5。拦光一般在第一面和最后一面操作,减少边缘无用光线。光阑面与镜面贴近,要调距离,同时设置光阑像差。后截距是指从镜头后表面到焦点的距离。CONS:弧度转为角度。镜头相互嵌入,有错误。

weixin_72050316的博客 600

UVA712 S树 S-Trees

无需建树,直接定位; 变量行无用; 输入有几个问题:cin+getline的组合会导致用getline输入的字符串丢失第一位,getline+getline第二个getline输入的字符串会丢失一位,输入的两行字符串第二个字符串可以用scanf读入。 另外,getline而入一行后不需要用getchar()读掉末尾的换行符,否则下一行字符串还是会丢失一位,可以理解为getline读入了换行符且作为了结束标志。 #include<iostream> #include<cstdio>.

gyp0205的博客 233

爬虫:一文掌握网站加密和混淆以及浏览器调试的技巧

面对加密和混淆技术的网站,传统的爬虫方法可能难以奏效。通过结合浏览器调试工具(如Puppeteer、Playwright)、代理工具(如Burp Suite、Fiddler)以及动态和静态分析技巧,可以深入理解网站的运行机制,绕过加密和混淆,实现有效的数据抓取。同时,务必注意合法合规,尊重目标网站的规则和用户的隐私,确保爬虫行为的正当性和可持续性。

数据知道的博客 9887

POJ1105 ZOJ1150 UVA712 UVALive5565 S-Trees【二叉树+模拟】

S-Trees Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 2272 Accepted: 1158 Description A Strange Tree (S-tree) over the variable set Xn = {x1,x2,…,xn} is a binary tree representing a Boo...

海岛Blog 625

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

S-Trees

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 cons...

wu1997___的博客 327

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

UVa 712

这个题根本不用建树,因为是完全二叉树,可以把这个想成二进制。对于根是二进制数的首位,之后依次类推。到最后的叶子节点就是从0到pow(2,n)-1。 关键在于在第一次输入的不是按照x1,x2,x3,x4这样的顺序输入的,那么我们就默认他的输入时按从二进制高位到地位。对于查询是按x1,x2,x3,x4这样的顺序。所以不能直接对应,需要一些小的操作来让查询的输入和二进制对的上。 1 ...

dieche3140的博客 172

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

UVA 712 S-Trees

S-Trees  A Strange Tree (S-tree) over the variable set is a binary tree representing a Boolean function . Each path of the S-tree begins at the root node and consists of n+1 node

小G的ACM之路 834

【树结构】poj1470/ZOJ1141

最近真的是连切水题都切不来了, 这个题的输入有点恶心。。 但是算法并不难,我用倍增lca水过了; 所谓倍增lca,就是用一个fa【x】【i】数组,记录离x这个节点网上2^i的节点是哪个。 fa【x】【i】=fa【fa【x】【i-1】】【i-1】; 话说Poj现在真是各种崩坏,只能转投zoj或者hdu了。。 附ZOJ1141代码,据说POJ加了新数据,导致过了ZOJ不一定能过POJ,所以

Pro_space的专栏 503

uva712-s树

1.x1,x2,x3是有用的他是每一个命令的顺序,例:x2,x1,x3 011,实际命令101 。2.要输出的数的位置就是实际命令的二进制

weixin_61556180的博客 254

UVA712 (好好读题)

0) ①敲题之前没理解清题意,输入的x1 x2 x3 是有用的...,要做相应的映射。 ②(0 int i=0;int res; res=pow(2,0); //res==1,没错 res=i ③自己试验时代码敲了freopen(),Submit前一定要去掉... 1) #include #include #include #include using namespac

他的博客 737

zoj 1905 Power String(后缀数组)

 题意:给定一个字符串L,已知这个字符串是由某个字符串S 重复R 次而得到的,求R 的最大值。 做法比较简单,穷举字符串S 的长度k,然后判断是否满足。判断的时候, 先看字符串L 的长度能否被k 整除,再看suffix(0)和suffix(k)的最长公共 前缀是否等于n-k。在询问最长公共前缀的时候,suffix(0)是固定的,所以RMQ 问题没有必要做所有的预处理, 只需求出hei

GODSPEED 855

poj 2127 zoj 2432 codeforces 10D 最长上升公共子序列

链接:http://poj.org/problem?id=2127 也不知怎么的就一下子一起搜到了这三个题,结果被坑了,在CF上AC的代码拿到poj 和 zoj都不能A,然后开始疯狂的造数据,终于被我造出了一组,然后发现开一维数组搞不定这个问题(反正我是搞不定了),于是还是老老实实的开了二维的dp,递归输出路径 这种DP应该很经典也很简单吧,dp[i][j]表示a数组的第i个数与b数组的第

努力奋斗才能梦想成真 1876

uva 712 二叉树

好好读题,尤其是input,关于xi会有一个对应关系,Eg:第一行输入x3, x2, x1, 然后输入100,那么实际要操作的指令是001#include &lt;cstdio&gt; #include &lt;cstring&gt; #include &lt;iostream&gt; #include &lt;string&gt; using namespace std; int main()...

GaoJieVery6 237

UVa712_S-Trees

题目:点击打开链接 思路:对于一节点k,其左右节点编号分别为2k,2k+1。然后模拟题意即可。原题输入比较多,但输入X1、X2.....没有用到。 #define _CRT_SECURE_NO_WARNINGS #include #include #include #include #include #include #include #include #include using names

sinat_17231979的专栏 504

UVa712 习题6-2 S树(S-Trees)

原题链接: UVA-712 题目大意:  模给一个序列集合VVI {x1, x2, x3, ....,xn}, VVI中不是0就是1。然后有一个n层的树,每一层同层的都是相同的一个数,这个数取自VVI中, 输入会给出每一层是VVI中的哪一个最后一层是叶子结点,上面是一串给定的数字。从跟结点出发,如果那个结点是0,就往左儿子方向走,如果是1就往右儿子方向走。最后落在最后一层的叶子结点上,

Miracle42的博客 1753

UVa 712 - S-Trees

传送门

一只冰熊 1155
上一篇: UVa 10050 Hartals(优先队列)
下一篇: UVa 297 Quadtrees(模拟&四分树)
synapse7
博客等级 码龄14年 432粉丝 701原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值