Trees on the level

本文探讨了二叉树的层次遍历算法,通过解析输入的二叉树序列,实现树的构建与遍历,并处理不完全指定的树结构。文章提供了完整的代码示例,展示了如何使用C++进行层次遍历的实现。

题目描述:

Trees are fundamental in many branches of computer science. Current state-of-the art parallel computers such as Thinking Machines’ CM-5 are based on fat trees. Quad- and octal-trees are fundamental to many algorithms in computer graphics.

This problem involves building and traversing binary trees.
Given a sequence of binary trees, you are to write a program that prints a level-order traversal of each tree. In this problem each node of a binary tree contains a positive integer and all binary trees have have fewer than 256 nodes.

In a level-order traversal of a tree, the data in all nodes at a given level are printed in left-to-right order and all nodes at level k are printed before all nodes at level k+1.

For example, a level order traversal of the tree
在这里插入图片描述
is: 5, 4, 8, 11, 13, 4, 7, 2, 1.

In this problem a binary tree is specified by a sequence of pairs (n,s) where n is the value at the node whose path from the root is given by the string s. A path is given be a sequence of L’s and R’s where L indicates a left branch and R indicates a right branch. In the tree diagrammed above, the node containing 13 is specified by (13,RL), and the node containing 2 is specified by (2,LLR). The root node is specified by (5,) where the empty string indicates the path from the root to itself. A binary tree is considered to be completely specified if every node on all root-to-node paths in the tree is given a value exactly once.

输入:

The input is a sequence of binary trees specified as described above. Each tree in a sequence consists of several pairs (n,s) as described above separated by whitespace. The last entry in each tree is (). No whitespace appears between left and right parentheses.

All nodes contain a positive integer. Every tree in the input will consist of at least one node and no more than 256 nodes. Input is terminated by end-of-file.

输出:

For each completely specified binary tree in the input file, the level order traversal of that tree should be printed. If a tree is not completely specified, i.e., some node in the tree is NOT given a value or a node is given a value more than once, then the string ``not complete’’ should be printed

样例输入:

(11,LL) (7,LLL) (8,R)
(5,) (4,L) (13,RL) (2,LLR) (1,RRR) (4,RR) ()
(3,L) (4,R) ()

样例输出:

5 4 8 11 13 4 7 2 1
not complete

作为一只蒟蒻的我,看到判断是否是树,总是莫名其妙想到的并查集???
但是仔细阅读,发现,,虽然也不是不能写,就是,,太麻烦啦,估计要好长好长
巨懒的我觉定看一下别人的思路,顺便学习一下
下面是总结之后的代码

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<map> 
using namespace std;
struct node{
	int x,y;
	string s;
}edge[1010];
map<string,int> feng;
bool cmp(node a,node b)
{
	if(a.y==b.y)return a.s<b.s;
	else return a.y<b.y;
}
int main()
{
	string a;
	int n=0,flag=0;
	while(cin>>a)
	{
		if(a=="()")
		{
			sort(edge,edge+n,cmp);
			if(flag==1||edge[0].y!=0)
			{
				printf("not complete\n");
			}
			else
			{
				for(int i=0;i<n;i++)
				{
					if(edge[i].y>0)
					{
						string ss="";
						int len=edge[i].s.length();
						for(int j=0;j<len-1;j++)
						{
							ss+=edge[i].s[j];
						}
						if(feng[ss]!=1)
						{
							flag=1;
							break;
						}
					}
				}
				if(flag==1)printf("not complete\n");
				else
				{
					for(int i=0;i<n;i++)
					{
						if(i!=0)printf(" ");
						printf("%d",edge[i].x);
					}
					printf("\n");
				 } 
			}
			n=flag=0;
			feng.clear();
		}
		else
		{
			int i;
			int num=0;
			for(i=1;i<a.length();i++)
			{
				if(a[i]==',')break;
				else
				{
					num=num*10+a[i]-'0';
				}
			}
			edge[n].x=num;
			edge[n].s.clear();
			num=0;
			for(i=i+1;i<a.length();i++)
			{
				if(a[i]==')')break;
				num++;
				edge[n].s+=a[i];
			}
			feng[edge[n].s]++;
			if(feng[edge[n].s]>1)flag=1;
			edge[n].y=num;
			n++;
		}
	} 
	return 0;
}
翻译:and a material design model, for simulating the characteristics of the semiconductor equipment. Mitrovic and Strang [19] applied the first-principle simulation to virtual sensor measurements to facilitate the process performed by the semiconductor processing tool. However, semiconductor manufacturing consists of hundreds of processing phases, months of processing time and correlative process flows [20]. The corresponding behavior analysis of the tool failure degradation process is very limited. Thus, the results provide neither reliable and accurate physical or mathematical models nor confident experience feedback for mechanism-based modeling. This is the main limitation of the applications of model-based approaches. In the knowledge-based methods, competitive advantages for stabilizing maintenance processes and reducing unplanned costs are realized by holistic consideration of production processes [21]. Prescriptive maintenance is known as the highest maturity and complexity level of knowledge-based maintenance [22], and “how can we control the occurrence of a specific event” should be answered and useful advice for decision-making to be given to improve and optimize the upcoming maintenance processes [23]. Nemeth et al. [22] built on the concept of prescriptive maintenance and proposed a reference model called PriMa-X to support the implementation of a prescriptive maintenance strategy and the assessment of its maturity level, facilitating the integration of data driven methods for predicting future events and identify action fields to reach an enhanced target maturity state. Padovano et al. [24] proposed a framework to construct the missing link between prescriptive maintenance and production planning and control functions in a cyber–physical production environment. Shaheen and Németh [25], Silvestri et al. [26], and Zonta et al. [27] discussed the prescriptive maintenance methods for Industry 4.0 technologies. Obtaining domain knowledge and converting it to precise rules are usually difficult as they require strong background and experience. Besides, the new situations without being covered by the knowledge bases cannot be handled. Data-driven methods are effective when acquiring practical data is more convenient than establishing physical or analytical models [28]. With the development of sensor techniques and wide applications of advanced process control technologies [29], the numerous manufacturing data provide wide opportunities for applying the data-driven prognostics methods to deal with the failure time prediction in the semiconductor manufacturing. Based on the monitoring data, the system degradation tendency can be easily understood and predicted. Generally, data-driven methods applied to the prognostics in the industry are adapted from the ones used in machine learning [29], [30]: neural networks [10], [31], k-nearest neighbor [32], [33], statistical methods [11], [34], decision trees [35], [36], clustering analysis [37], [38], and so on. Regarding the prognostics in semiconductor manufacturing, Bouaziz et al. [40] addressed a predictive approach based on the Bayesian network to analyze the device health factor. It allows early scheduling for preventive maintenance and avoids unscheduled tool downtime. Jia et al. [41] developed an adaptive method on the basis of the polynomial neural network to infer the material removal rate in the chemical-mechanical planarization process of the semiconductor fabrication. Yang and Lee [42] applied the Bayesian belief network to analyze the causal relationship of the process variables and estimate their effects on wafer quality to achieve high-classification rates for wafer quality and identify the problematic sensors when any bad wafer is detected. In reality, the quantity and quality of the data collected from the processes are problematic when it comes to developing and maintaining effective data-driven prognostics models [43]. As the failure can be slowly accumulated, the relevant data for evaluating the failure behavior would be scarce. In addition, most data-driven prognostics methods in semiconductor manufacturing focus on the deterministic estimation without giving the confidence level of the inference of the tool failure prognostics, which implies how much effect on the accuracy of the prognostic models built upon the acquired data is unknown. Using the poorly monitoring data would result in an improper estimation of the cleaning time. For more accurate prognostics, it is necessary to have a good and reliable prognostic model. As the tool failure mechanisms and uncertainty in semiconductor manufacturing are complex and unavailable, this article proposes a data-driven prognostic method to study the failure behavior and predict the tendency on the basis of the obtained production data in the fabrication process. One of the achievements is implementing the prognostics for determining the explicit cleaning time and reducing the dependence on the mechanism analysis. A novel failure factor extraction and prognostic model is developed based on autoassociative regression (AR)-Gaussian process (GP), which is the integration of the AR [44] and the GP [45]. It can be used to analyze and extract the failure factors by the comparisons between the actual data and the fault-free data. Furthermore, with the analysis of the residual tendency, the abnormalities can be detected to be used as the variables of the prognostic model. To infer the future failure behaviors in the fabrication process of semiconductor manufacturing, the data-driven prognostic model is constructed on the basis of GP to present the degradation evolution in a probability distribution and evaluate the uncertainty. Thanks to the confident interval of each estimated value, the accuracy of the prediction influenced by the collected data quality can be presented. It cannot be done by the deterministic estimation. And the suitable cleaning time for the fabrication process is given based on the discussion of the possible failure phenomena in semiconductor manufacturing. This article is structured as follows. The prognostic problem in semiconductor manufacturing is defined and its issues are discussed in Section II. Section III details the novel AR-GP method. The feasibility and the promising results of the ARGP method are validated through a numerical example and a practical semiconductor manufacturing process for the failure factor extraction and failure behavior inference, respectively, in Section IV. Finally, Section V draws conclusions.
最新发布
11-24
半导体制造中的故障预测方法可分为三类,现就关键内容进行翻译和分析: 1. **模型驱动方法的局限**: - 现有模型(如Takako的3D设备仿真模型或Mitrovic的第一性原理模拟)难以覆盖数百道制程环节和长达数月的生产流程 - 设备退化行为的对应分析非常有限,既无法提供可靠的物理/数学模型,也缺乏有效的经验反馈机制 2. **知识驱动方法的进展**: - 预测性维护(Prescriptive Maintenance)作为最高成熟度层级,通过PriMa-X等参考模型实现决策优化 - 在工业4.0环境中构建与生产计划控制的数字孪生链接(如Padovano框架) - 核心挑战:领域知识获取与规则转化困难,难以处理知识库未覆盖的新场景 3. **数据驱动方法的实践**: ```python # 半导体制造中典型数据驱动预测示例(基于贝叶斯网络) import pymc3 as pm def build_bayesian_network(sensor_data): with pm.Model() as model: # 定义先验分布(设备健康因子) health_factor = pm.Normal('health', mu=0, sigma=1) # 定义观测节点(传感器读数似然函数) obs = pm.Poisson('obs', mu=pm.math.exp(health_factor), observed=sensor_data) # MCMC采样推断 trace = pm.sample(1000) return trace ``` - 应用场景: - Bouaziz的贝叶斯网络实现预防性维护调度 - Yang的贝叶斯信念网络分析晶圆质量因果关系 - 现存问题: - 数据质量影响模型有效性(故障数据稀疏) - 多数方法缺乏置信度评估(确定性估计局限) 4. **本文创新方法AR-GP**: - 通过自回归高斯过程(Auto-regressive Gaussian Process)整合: - 残差趋势分析检测异常变量 - 概率分布表征退化演化过程 - 核心优势: - 量化预测不确定性(置信区间) - 减少对机理分析的依赖
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值