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

AgentFlow:模块化智能体框架与Flow-GRPO强化学习实战解析 在人工智能领域,大语言模型(LLM)与智能体(Agent)技术正推动着自动化任务处理的发展。其核心原理在于通过规划、执行与反馈的循环,使AI系统能够自主调用工具解决复杂问题。这一技术的价值在于突破单一模型的局限性,实现更可靠的多步骤推理。在实际应用中,智能体框架需要处理搜索、代码执行、数学计算等多种场景。本文聚焦的AgentFlow框架,正是通过模块化设计将智能体拆分为规划者、执行者、验证者和生成者四个专家模块,并引入Flow-GRPO强化学习算法进行流程内优化。该框架在搜索增强与工具调用等任务上展现出显著 阅读详情

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


MTK平台WiFi学习--Wi-Fi 连线/断线问题初步分析 摘要:本文详细介绍了MTK平台WiFi连接问题的日志分析方法。文章首先阐述了WiFi连接的标准流程,包括指令接收、BSSID选择、信道分配、认证关联、四次握手和DHCP获取等关键步骤。针对常见故障场景,如选网失败、信道申请失败、认证关联失败、四次握手失败等,提供了具体的日志分析方法和排查思路,包括识别关键日志、分析状态码、结合固件日志和抓包数据等。文章还特别强调了不同故障场景下需要收集的日志类型和分析要点,为WiFi连接问题的定位提供了一套系统化的解决方案。 阅读详情

相关推荐

华为服务器RAID配置避坑指南:如何通过iBMC快速识别阵列卡型号并完成初始化

本文详细解析华为服务器RAID配置全流程,重点介绍通过iBMC快速识别阵列卡型号、硬盘健康诊断及RAID级别选择的场景化策略。提供从iBMC登录到缓存策略调优的实战技巧,帮助工程师避免常见配置陷阱,提升服务器存储系统性能和稳定性。

weixin_28475533的博客 490

[UVa 712] S 树(S-Trees)

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

StarlitNight的博客 672

从零开始:如何用Python建立你的第一个人工智能模型

在这篇文章中,我们将介绍如何从零开始使用Python建立你的第一个人工智能模型。无论你是刚接触编程的新手,还是有经验的开发者想进一步探索人工智能领域,这篇文章都将为你提供清晰、详细的指南。我们将一步步探索数据预处理、模型建立、训练和测试的过程,以及如何解读模型的结果。

Allen1862105的博客 4万+

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

优雅谈大模型:“System2”与“System 1”

研究人员探索了三种System 2方法——RaR、S2A 和 BSM,这些方法已经成功提炼到新的LLM,这个新的模型与System 1相比,产生了更好的结果,而且成本低于System 2。然而这种方法是有局限性,只能适用于特定的任务。

鲁班模锤 5148

别再为通讯发愁了!手把手教你用PCAN-View调试Kinco步科伺服电机的CANopen

本文详细介绍了如何使用PCAN-View工具调试Kinco步科伺服电机的CANopen通讯,从环境搭建到实战演练,涵盖硬件连接、软件配置及故障排除。通过具体案例和代码示例,帮助工程师快速掌握伺服电机通讯控制技术,解决工业设备通讯难题。

weixin_29189377的博客 266

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

避坑指南:从聚宽迁移到QMT必须知道的5个细节(含Redis连接异常处理)

本文详细解析了从聚宽迁移到QMT平台时需注意的5个关键细节,特别是Redis连接池优化和xtquant重连机制。通过实战代码示例,帮助量化团队解决信号传递稳定性、时间同步、滑点控制等核心问题,确保交易策略平稳过渡。

weixin_27303545的博客 426

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

LeetCode 热题 100 回顾

力扣最受刷题发烧友欢迎的 100 道题 LeetCode 热题 100 : 题目回顾、解题思路、复杂度分析、代码实现、验证算法

曾经“等你生日那天”都遥远得像未来,如今却可欢愉的挥手说“下个十年见” 9万+

药物对接仿真软件:HADDOCK_(9).结果分析方法

HADDOCK是一种强大的药物对接仿真工具,通过对生成的输出文件进行详细的分析,我们可以验证仿真结果的可靠性,并为进一步优化药物设计提供依据。常见的分析方法包括解读输出文件、使用可视化工具进行结构分析、评估对接模型的稳定性和准确性等。通过这些步骤,我们可以更全面地了解受体和配体的结合模式,从而提高药物设计的成功率。

kkchenjj的博客 1006

UVA712 S树 S-Trees

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

gyp0205的博客 233

工业相机的检测原理课件(建议收藏)

本课件为各位工程师详细介绍了工业相机的视觉检测原理 ,旨在为工程师调试工业相机的视觉检测原理时提供理论性指导。

Bamboo265925的博客 498

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

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

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

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

UVa 712

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

dieche3140的博客 172

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

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、付费专栏及课程。

余额充值