专题一 数据结构
空间数据结构

空间数据结构数据结构定义:指数据组织的形式,是指适合于计算机存储、管理和处理的数据逻辑结构,地理实体的空间排列方式和相互关系的抽象描述,对数据的一种理解和解释。
空间数据的三大特性:空间,时间,专题属性。
常见的数据结构:矢量结构,栅格结构,数字高程模型,面向对象模型,矢量和栅格的混合数据结构等,网络结构,空间数据编码:1、空间数据结构的实现2将搜集的、经过审核了的地形图、专题地图和遥感影像等资料按特定的数据结构转换为适合于计算机存储和处理的数据的过程3在地理信息系统的空间数据结构中栅格结构的编码方式:直接栅格编码、链码、游程长度编码、块码、四叉树码等矢量结构主要有坐标序列编码、树状索引编码和二元拓扑编码等编码方3.2 栅格数据结构一、概述1、栅格数据结构是基于空间划分或铺盖的空间被划分成大量规则的或不规则的空间单元,称为象素(Cell或Pixel),依行列构成的单元矩阵叫栅格(Grid)三角形方格六角形2、每个单元通过一定的数值表达方式(如颜色、灰度级)表达诸如环境污染程度、植被覆盖类型等空间地理现象3、对同一现象,也可能有若干不同尺度、不同聚分性的铺盖4、目前常用的是基于正方型分划的栅格,是指将地球表面划分为大小均匀紧密相邻的网格阵列每个网格作为一个象元或象素由行、列定义包含一个代码表示该象素的属性类型或量值,或仅仅包括指向其属性记录的指针5 、栅格数据的比例尺就是栅格大小与地表相应单元大小之比6 、GIS中栅格数据经常是来自卫星遥感、摄影测量、激光雷达和扫描设备中,以及用于数字化文件的设备中二、栅格数据组织1 、以规则的阵列来表示空间地物或现象分布的数据组织2 、每个数据表示地物或现象的非几何属性特征点状地物用一个栅格单元表示;线状地物沿线走向的一组相邻栅格单元表示面或区域用记有区域属性的相邻栅格单元的集合表示3 、遥感影像属于典型的栅格结构,每个象元的数字表示影像的灰度等级三、栅格结构的建立(1)栅格数据的获取途径遥感数据图片的扫描矢量数据转换:手工方法获取: 在专题图上均匀划分网格,逐个网格地确定其属性代码的值,最后形成栅格数据文件(2)栅格系统的确定栅格坐标系的确定:坐标系的确定实质是坐标系原点和坐标轴的确定由于栅格编码一般用于区域性GIS,原点的选择常具有局部性质为了便于区域的拼接,栅格系统的起始坐标应与国家基本比例尺地形图公里网的交点相一致,并分别采用公里网的纵横坐标轴作为栅格系统的坐标轴。
抽象数据类型

集合结构是整个数据结构中的一种特殊情况,其元素之间不存在任何关系。 【例 1.5】一种数据结构的二元组表示为 B=(K,R),其中
数据的逻辑结构通常采用二元组来描述,其中一元为数据元素的集合,另一元为元素 之间逻辑关系的集合,每一个逻辑关系是元素序偶的集合,如<x,y>就是一个序偶,其中 x 为前驱,y 为后继。当数据的逻辑结构存在着多个逻辑关系时,通常对每个关系分别进行 讨论。
逻辑结构的另一种描述方法是图形表示,图中每个结点表示元素,每条带箭头的连线 表示元素之间的前驱与后继的关系,其箭头一端为后继元素,另一端为前驱元素。
专题 1 数据结构分类与抽象数据类型
5
若数据是线性结构、树结构或图结构,则除了要存储所有数据元素外,还要相应存储元素 之间的线性关系、层次关系或网状关系。
数据的存储结构分为顺序、链接、索引和散列 4 种。 顺序存储对应一块连续的存储空间,该空间的大小要大于等于存储所有元素需占有的 存储空间的大小,存储元素之间的联系(即逻辑结构)通常不需要附加空间,而是通过元 素下标之间的对应关系反映出来,只要简单的计算就可以得到一个元素的前驱或后继元素 的下标。顺序存储空间一般需要通过定义数组类型和数组对象来实现。 在链接存储结构中,元素之间的逻辑关系通过存储结点之间的链接关系反映出来,每 个存储结点对应存储一个元素,同时存储该元素的前驱和后继元素所在结点的存储位置, 或者说同时存储指向其前驱元素结点和后继元素结点的指针,通过这些指针能够直接访问 到其前驱元素和后继元素。链接存储空间通过定义元素的存储结点类型和对象来实现,所 有存储结点可以占用连续的存储空间(即数组空间),也可以占用不连续的存储空间,此 空间是由动态分配的每个结点的空间形成的。 索引存储是首先把所有数据元素按照一定的函数关系划分成若干个子表,每个子表对 应一个索引项,然后采用一种存储结构存储所有子表的索引项和采用另一种存储结构存储 所有子表中的元素。如存储汉字字典时,需要采用索引存储,首先按偏旁部首划分所存汉 字为若干子表,得到偏旁部首表,对于每个部首再按所属汉字的笔画多少划分子表,得到 检字表,检字表中的每个汉字对应汉字解释表(即字典主体)中的一个条目;然后再分别 存储部首表、检字表和汉字解释表。这里检字表是汉字解释表的索引,而偏旁部首表又是 检字表的索引,它是汉字解释表的二级索引。当存储的数据量很大时,通常都需要采用索 引存储,并且时常使用多级索引。 在索引存储中,各级索引表和主表(即数据元素表)通常都以文件的形式保存在外存 磁盘上,访问任一数据元素时,都要根据该数据元素的特征依次访问各级索引表和最后访 问主表,存取外存的次数至少等于建立索引的级数加 1。 散列存储方法是按照数据元素的关键字通过一种函数变换直接得到该元素存储地址的 方法,该存储地址为相应数组空间中的下标位置。用于散列存储所有数据元素的相应数组 空间称为散列表。通过定义用于计算散列存储地址的函数和定义存储数据元素的散列表能 够实现散列存储结构。 以上简要叙述了数据结构的有关概念,在以后的各专题中将会做深入和具体的讨论。
国家计算机二级VFP资料

表对应一个关系; 类型:1:1, n:1, 1:n, m:n 运算:交、并、差(要求两个关系必须具有 更新规则:级联、限制、忽略 相同的结构) 投影(列)、选择(行)、 删除规则:级联、限制、忽略 揑入规则:限制、忽略 自然 连接(相同字段) 完整性:实体完整性(主码/主索引)、域完 整性(有效性规则)、参照完整性(关系)
变量的作用域: ①.公共变量(public):作用于程序运行的始终 ②.局部变量(local):只在本过程中使用,即不上传,也不接收 ③.私有变量(private):不上传、可以接收(默认) 注意:local变量具有隐藏上层模块中建立的同名变量的作用; private变量也具有隐藏上层模块中建立的同名变量的作用。
第二章 第三章 第四章
数据结构与算法
程序设计基础 软件工程基础 数据库设计基础
DB、DBMS、DBS、DBAS () 三级模式:模式(逻辑/概念)、内模式(物理 P16 /存储)、外模式(用户) P15 层次模型、网状模型、关系模型
主关键字与外部关键字(外码)
P13
P32
定义:一个关系就是一张二维表,一张二维 学生与学校两个实体之间的关系属于
二、程序设计基础 1. 程序设计方法与风格。 2. 结构化程序设计。 3. 面向对象的程序设计方法,对象,方法,属性及继承与 多态性。 三、软件工程基础 1. 软件工程基本概念,软件生命周期概念,软件工具与软 件开发环境。 2. 结构化分析方法,数据流图,数据字典,软件需求规格 说明书。 3. 结构化设计方法,总体设计与详细设计。 4. 软件测试的方法,白盒测试与黑盒测试,测试用例设计, 软件测试的实施,单元测试、集成测试和系统测试。 5. 程序的调试,静态调试与动态调试。
硬盘数据结构

《数据结构》课程标准

01
分支限界策略
类似于回溯法,但在搜索过程中通过 剪枝等操作来减少搜索空间,提高效 率。
05
03
贪心策略
每一步都采取当前状态下最好或最优 的选择,从而希望导致结果是全局最 好或最优的。
04
回溯策略
通过探索所有可能的解来求解问题, 当发现当前路径无法得到解时,回溯 到上一步重新选择。
05
排序与查找算法专题
《数据结构》课程标准
目录
• 课程概述与目标 • 基本数据类型与操作 • 复杂数据类型与操作 • 算法设计与分析基础 • 排序与查找算法专题 • 文件组织与处理技术 • 实验环节与项目实践指导
01
课程概述与目标
数据结构定义及重要性
数据结构定义
数据结构是计算机存储、组织数据的方式,指相互之间存在一种或多种特定关 系的数据元素的集合。
01
02
03
时间复杂度
衡量算法执行时间随问题 规模增长的速度,常用大 O表示法。
空间复杂度
衡量算法执行过程中所需 额外空间的数量级,也常 用大O表示法。
其他指标
包括算法的稳定性、可读 性、可维护性等。
典型算法设计策略
分治策略
将原问题分解为若干个子问题,分别 求解后再合并结果。
02
动态规划
通过保存子问题的解,避免重复计算, 提高效率。
06
文件组织与处理技术
文件概念及分类方法
文件定义
文件是存储在外部介质上的数据集合, 通常以记录为单位进行组织。
文件分类
根据文件的性质和记录的组织方式,文 件可分为顺序文件、索引文件、散列文 件和链式文件等。
顺序文件组织方式
顺序文件的定义
顺序文件是按照某种顺序 (如记录的逻辑顺序或物 理顺序)进行组织的文件。
三个模块,两大单元,一专题

三个模块,两大单元,一专题
您说的“三个模块,两大单元,一专题”可能是在某种教育或培训框架下的一种组织结构。
这种结构将内容分为不同的部分,以便于学习和教学。
1. 三个模块:通常是指三个主要的、互相关联的部分。
每个模块可能涵盖了特定的主题或技能集合。
例如,在编程培训中,一个模块可能涵盖基础语法、数据结构和算法等。
2. 两大单元:这通常指的是在某个大主题下分成的两个主要部分或子主题。
例如,在某个关于历史的课程中,一个单元可能专注于古代历史,另一个单元则专注于中世纪历史。
3. 一专题:这通常指的是一个更为集中、深入的研究或讨论主题。
它可能是一个更为专业或具体的子主题,例如某个历史事件、人物或思想流派。
这样的结构可以帮助组织内容,使其更有条理,并帮助学习者更好地理解和吸收信息。
如果您是在考虑某个特定的课程或培训项目,建议您进一步了解该项目的具体内容,以获得更详细和准确的信息。
空间数据结构

第五章空间数据结构数据结构即指数据组织的形式,是适合于计算机存储、管理和处理的数据逻辑结构。
地理信息系统空间数据结构是指空间数据在系统内的组织和编码形式(GIS数据结构也可称为图形数据格式),它是指适合于计算机系统存储、管理和处理地理图形的逻辑结构。
GIS中,空间数据一般有着较为复杂的数据结构,目前,主要有两种数据模型表示空间数据,即矢量数据模型和栅格数据模型。
4.1 栅格数据结构4.1.1概述栅格数据是计算机和其它信息输入输出设备广泛使用的一种数据模型,如电视机、显示器、打印机等的空间寻址。
甚至专门用于矢量图形的输入输出设备,如数字化仪、矢量绘图仪及扫描仪等,其内部结构实质上是栅格的。
遥感数据也是采用特殊扫描平台获得的栅格数据。
栅格数据就是用数字表示的像元阵列,其中,栅格的行和列规定了实体所在的坐标空间,而数字矩阵本身则描述了实体的属性或属性编码。
栅格数据最显著的特点就是存在着最小的、不能再分的栅格单元,在形式上常表现为整齐的数字矩阵,因而便于计算机进行处理,特别是存储和显示。
4.1.2编码方案以图4-1为例,介绍几种编码方法的编码思路、方案和特点。
图4-1 栅格数据结构1. 游程长度编码地理数据往往有较强的相关性,也就是说相邻象元的值往往是相同的。
游程长度编码的基本思想是:按行扫描,将相邻等值的象元合并,并记录代码的重复个数。
游程长度编码的数据结构: 行号,属性,重复次数。
图4-1的游程长度编码为:1,A,4,R,1,A,6…对于游程长度编码,区域越大,数据的相关性越强,则压缩越大。
其特点是,压缩效率较高,叠加、合并等运算简单,编码和解码运算快。
2. 块式编码块式编码是将游程扩大到二维情况,把多边形范围划分成若干具有同一属性的正方形,然后对各个正方形进行编码。
块式编码的基本思想:由初始位置(行列号)、半径和属性代码组成。
图4-1的块状编码为:(1,1,3,A),(1,5,1,R),(1,6,2,A),…块状编码对大而简单的多边形更为有效,对一些虽不较多的复杂多边形效果并不好。
《数据结构》教学大纲

《数据结构》教学大纲一、课程基本信息二、课程描述(一)课程简介《数据结构》是信息类各专业的核心基础课程,是一门理论与实践相结合的课程,在整个信息相关专业的教学体系中处于举足轻重的地位。
数据结构是设计和实现编译程序、操作系统、数据库系统及其它系统程序和大型应用程序的重要基础。
通过本课程理论和实践的教学,使学生较牢固地掌握数据结构的基本概念、原理、算法,了解算法复杂性的度量方法,初步掌握根据所求解问题的性质选择合理的数据结构,并对时间空间复杂性进行必要的控制,培养和提高学生理论、抽象、设计的能力,掌握数据结构和算法的设计分析技术,提高程序设计的质量,为将来的研究和开发工作打下坚实的基础。
“Data Structures and Algorithms”, one of the most important core courses in Computer Science. The course also covers fundamental data structures and classical algorithms which are widely used in the succeeding specialized courses,such as Operating Systems, Software Engineering, Database Systems, Compiler Principles, Computer Graphics and Human Computer Interaction.What is the combination of data structures and algorithms? Niklaus Wirth wrote a book titled "Algorithms + Data Structures = Programs", which points out their important roles in computing discipline:algorithm and data structure are two closely linked and indivisible parts of programming.The course will follow the idea of“Algorithms + Data Structures = Programs”, aimed at improving students’ knowledge and skills of theory, abstraction and design in problem solving.This course will focus on data structures and algorithms for manipulating them. Data structures for storing information in tables, lists, trees, queues and stacks will be covered. Some basic graph and discrete transform algorithms will also be discussed. On a solid basis of the fundamental theory, the students will analyze the problems using problem, data and algorithm abstraction. Making a tradeoff between space and time complexity, the students will learn how to organize data reasonably, design efficient and effective algorithms, and implement high quality programs, so that they can solve real-world complex problems.After studying the course, the students’ ability of abstract thinking and problem solving should have improvedconsiderably.Their programming skills and the quality of their codes would have increased as well. After studying this course, students should be well prepared for further study, engineering and research in computer related areas.(二)课程教学基本设计本课程由大班授课、小班讨论和实验组成,学时分配分别为48学时、16学时、16学时。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Problem A : Hardwood SpeciesFrom:POJ, 2418DescriptionHardwoods are the botanical group of trees that have broad leaves, produce a fruit or nut, and generally go dormant in the winter.America's temperate climates produce forests with hundreds of hardwood species -- trees that share certain biological characteristics. Although oak, maple and cherry all are types of hardwood trees, for example, they are different species. Together, all the hardwood species represent 40 percent of the trees in the United States.On the other hand, softwoods, or conifers, from the Latin word meaning "cone-bearing," have needles. Widely available US softwoods include cedar, fir, hemlock, pine, redwood, spruce and cypress. In a home, the softwoods are used primarily as structural lumber such as 2x4s and 2x6s, with some limited decorative applications.Using satellite imaging technology, the Department of Natural Resources has compiled an inventory of every tree standing on a particular day. You are to compute the total fraction of the tree population represented by each species.InputInput to your program consists of a list of the species of every tree observed by the satellite; one tree per line. No species name exceeds 30 characters. There are no more than 10,000 species and no more than 1,000,000 trees.OutputPrint the name of each species represented in the population, in alphabetical order, followed by the percentage of the population it represents, to 4 decimal places.Sample InputRed AlderAshAspenBasswoodAshBeechYellow BirchAshCherryCottonwoodAshCypressRed ElmGumHackberryWhite OakHickoryPecanHard MapleWhite OakSoft MapleRed OakRed OakWhite OakPoplanSassafras SycamoreBlack WalnutWillowSample OutputAsh 13.7931Aspen 3.4483 Basswood 3.4483 Beech 3.4483Black Walnut 3.4483 Cherry 3.4483 Cottonwood 3.4483 Cypress 3.4483 Gum 3.4483 Hackberry 3.4483 Hard Maple 3.4483 Hickory 3.4483 Pecan 3.4483 Poplan 3.4483Red Alder 3.4483 Red Elm 3.4483Red Oak 6.8966 Sassafras 3.4483 Soft Maple 3.4483 Sycamore 3.4483 White Oak 10.3448 Willow 3.4483Yellow Birch 3.4483HintThis problem has huge input, use scanf instead of cin to avoid time limit exceeded.Problem B : Nearest Common AncestorsFrom:POJ, 1330DescriptionA rooted tree is a well-known data structure in computer science and engineering. An example is shown below:In the figure, each node is labeled with an integer from {1, 2,...,16}. Node 8 is the root of the tree. Node x is an ancestor of node y if node x is in the path between the root and node y. For example, node 4 is an ancestor of node 16. Node 10 is also an ancestor of node 16. As a matter of fact, nodes 8, 4, 10, and 16 are the ancestors of node 16. Remember that a node is an ancestor of itself. Nodes 8, 4, 6, and 7 are the ancestors of node 7. A node x is called a common ancestor of two different nodes y and z if node x is an ancestor of node y and an ancestor of node z. Thus, nodes 8 and 4 are the common ancestors of nodes 16 and 7. A node x is called the nearest common ancestor of nodes y and z if x is a common ancestor of y and z and nearest to y and z among their common ancestors. Hence, the nearest common ancestor of nodes 16 and 7 is node 4. Node 4 is nearer to nodes 16 and 7 than node 8 is.For other examples, the nearest common ancestor of nodes 2 and 3 is node 10, the nearest common ancestor of nodes 6 and 13 is node 8, and the nearest common ancestor of nodes 4 and 12 is node 4. In the last example, if y is an ancestor of z, then the nearest common ancestor of y and z is y.Write a program that finds the nearest common ancestor of two distinct nodes in a tree.InputThe input consists of T test cases. The number of test cases (T) is given in the first line of the input file. Each test case starts with a line containing an integer N , the number of nodes in a tree, 2<=N<=10,000. The nodes are labeled with integers 1, 2,..., N. Each of the next N -1 lines contains a pair of integers that represent an edge --the first integer is the parent node of the second integer. Note that a tree with N nodes has exactly N - 1 edges. The last line of each test case contains two distinct integers whose nearest common ancestor is to be computed.OutputPrint exactly one line for each test case. The line should contain the integer that is the nearest common ancestor.Sample Input2161 148 510 165 94 68 44 101 136 1510 116 710 216 38 116 1216 752 33 43 11 53 5Sample Output43Problem C : ExpressionsFrom:POJ, 3367DescriptionArithmetic expressions are usually written with the operators in between the two operands (which is called infix notation). For example, (x+y)*(z-w) is an arithmetic expression in infix notation. However, it is easier to write a program to evaluate an expression if the expression is written in postfix notation (also known as reverse Polish notation). In postfix notation, an operator is written behind its two operands, which may be expressions themselves. For example, x y + z w - * is a postfix notation of the arithmetic expression given above. Note that in this case parentheses are not required.To evaluate an expression written in postfix notation, an algorithm operating on a stack can be used. A stack is a data structure which supports two operations:1.push: a number is inserted at the top of the stack.2.pop: the number from the top of the stack is taken out.During the evaluation, we process the expression from left to right. If we encounter a number, we push it onto the stack. If we encounter an operator, we pop the first two numbers from the stack, apply the operator on them, and push the result back onto the stack. More specifically, the following pseudocode shows how to handle the case when we encounter an operator O:a := pop();b := pop();push(b O a);The result of the expression will be left as the only number on the stack.Now imagine that we use a queue instead of the stack. A queue also has apush and pop operation, but their meaning is different:1.push: a number is inserted at the end of the queue.2.pop: the number from the front of the queue is taken out of the queue.Can you rewrite the given expression such that the result of the algorithm using the queue is the same as the result of the original expression evaluated using the algorithm with the stack?InputThe first line of the input contains a number T (T ≤ 200). The following T lines each contain one expression in postfix notation. Arithmetic operators are represented by uppercase letters, numbers arerepresented by lowercase letters. You may assume that the length of each expression is less than 10000 characters.OutputFor each given expression, print the expression with the equivalent result when using the algorithm with the queue instead of the stack. To make the solution unique, you are not allowed to assume that the operators are associative or commutative.Sample Input2xyPzwIMabcABdefgCDEFSample OutputwzyxIPMgfCecbDdAaEBFProblem D : Navigation NightmareFrom:POJ, 1984DescriptionFarmer John's pastoral neighborhood has N farms (2 <= N <= 40,000), usually numbered/labeled 1..N. A series of M (1 <= M < 40,000) vertical and horizontal roads each of varying lengths (1 <= length <= 1000) connect the farms. A map of these farms might look something like the illustration below in which farms are labeled F1..F7 for clarity and lengths between connected farms are shown as (n):F1 --- (13) ---- F6 --- (9) ----- F3| |(3) || (7)F4 --- (20) -------- F2 || |(2) F5|F7Being an ASCII diagram, it is not precisely to scale, of course.Each farm can connect directly to at most four other farms via roads that lead exactly north, south, east, and/or west. Moreover, farms are only located at the endpoints of roads, and some farm can be found at every endpoint of every road. No two roads cross, and precisely one path(sequence of roads) links every pair of farms.FJ lost his paper copy of the farm map and he wants to reconstruct it from backup information on his computer. This data contains lines like the following, one for every road:There is a road of length 10 running north from Farm #23 to Farm #17There is a road of length 7 running east from Farm #1 to Farm #17...As FJ is retrieving this data, he is occasionally interrupted by questions such as the following that he receives from his navigationally-challenged neighbor, farmer Bob:What is the Manhattan distance between farms #1 and #23?FJ answers Bob, when he can (sometimes he doesn't yet have enough data yet). In the example above, the answer would be 17, since Bob wants to know the "Manhattan" distance between the pair of farms. The Manhattan distance between two points (x1,y1) and (x2,y2) is just |x1-x2| + |y1-y2| (which is the distance a taxicab in a large city must travel over city streets in a perfect grid to connect two x,y points).When Bob asks about a particular pair of farms, FJ might not yet have enough information to deduce the distance between them; in this case, FJ apologizes profusely and replies with "-1".Input* Line 1: Two space-separated integers: N and M* Lines 2..M+1: Each line contains four space-separated entities, F1,F2, L, and D that describe a road. F1 and F2 are numbers oftwo farms connected by a road, L is its length, and D is acharacter that is either 'N', 'E', 'S', or 'W' giving thedirection of the road from F1 to F2.* Line M+2: A single integer, K (1 <= K <= 10,000), the number of FB's queries* Lines M+3..M+K+2: Each line corresponds to a query from Farmer Bob and contains three space-separated integers: F1, F2, and I. F1 and F2 are numbers of the two farms in the query and I is the index (1 <= I <= M) in the data after which Bob asks thequery. Data index 1 is on line 2 of the input data, and so on. Output* Lines 1..K: One integer per line, the response to each of Bob'squeries. Each line should contain either a distancemeasurement or -1, if it is impossible to determine theappropriate distance.Sample Input7 61 6 13 E6 3 9 E3 5 7 S4 1 3 N2 4 20 W4 7 2 S31 6 11 4 32 6 6Sample Output13-110HintAt time 1, FJ knows the distance between 1 and 6 is 13.At time 3, the distance between 1 and 4 is still unknown.At the end, location 6 is 3 units west and 7 north of 2, so the distance is 10.Problem E : Binary Search Heap ConstructionFrom:POJ, 1785DescriptionRead the statement of problem G for the definitions concerning trees. In the following we define the basic terminology of heaps. A heap is a tree whose internal nodes have each assigned a priority (a number) such that the priority of each internal node is less than the priority of its parent. As a consequence, the root has the greatest priority in the tree, which is one of the reasons why heaps can be used for the implementation of priority queues and for sorting.A binary tree in which each internal node has both a label and a priority, and which is both a binary search tree with respect to the labels and a heap with respect to the priorities, is called a treap. Your task is, given a set of label-priority-pairs, with unique labels and unique priorities, to construct a treap containing this data.InputThe input contains several test cases. Every test case starts with an integer n. You may assume that1<=n<=50000. Then follow n pairs of strings and numbers l1/p1,...,ln/pn denoting the label and priority of each node. The strings are non-empty and composed of lower-case letters, and the numbers are non-negative integers. The last test case is followed by a zero.OutputFor each test case output on a single line a treap that contains the specified nodes. A treap is printed as (< left sub-treap >< label >/< priority >< right sub-treap >). The sub-treaps are printed recursively, and omitted if leafs.Sample Input7 a/7 b/6 c/5 d/4 e/3 f/2 g/17 a/1 b/2 c/3 d/4 e/5 f/6 g/77 a/3 b/6 c/4 d/7 e/2 f/5 g/1Sample Output(a/7(b/6(c/5(d/4(e/3(f/2(g/1)))))))(((((((a/1)b/2)c/3)d/4)e/5)f/6)g/7)(((a/3)b/6(c/4))d/7((e/2)f/5(g/1)))Problem F : Cube StackingFrom:POJ, 1988DescriptionFarmer John and Betsy are playing a game with N (1 <= N <= 30,000)identical cubes labeled 1 through N. They start with N stacks, each containing a single cube. Farmer John asks Betsy to perform P (1<= P <= 100,000) operation. There are two types of operations:moves and counts.* In a move operation, Farmer John asks Bessie to move the stack containing cube X on top of the stack containing cube Y.* In a count operation, Farmer John asks Bessie to count the number of cubes on the stack with cube X that are under the cube X and report that value.Write a program that can verify the results of the game.Input* Line 1: A single integer, P* Lines 2..P+1: Each of these lines describes a legal operation. Line 2 describes the first operation, etc. Each line begins with a 'M' for a move operation or a 'C' for a count operation. For move operations, the line also contains two integers: X and Y.For count operations, the line also contains a single integer: X.Note that the value for N does not appear in the input file. No move operation will request a move a stack onto itself.OutputPrint the output from each of the count operations in the same order as the input file.Sample Input6M 1 6C 1M 2 4M 2 6C 3C 4Sample Output12Problem G : Find them, Catch themFrom:POJ, 1703DescriptionThe police office in Tadu City decides to say ends to the chaos, as launch actions to root up the TWO gangs in the city, Gang Dragon and Gang Snake. However, the police first needs to identify which gang a criminal belongs to. The present question is, given two criminals; do they belong to a same clan? You must give your judgment based on incomplete information. (Since the gangsters are always acting secretly.)Assume N (N <= 10^5) criminals are currently in Tadu City, numbered from 1 to N. And of course, at least one of them belongs to Gang Dragon, and the same for Gang Snake. You will be given M (M <= 10^5) messages in sequence, which are in the following two kinds:1. D [a] [b]where [a] and [b] are the numbers of two criminals, and they belong to different gangs.2. A [a] [b]where [a] and [b] are the numbers of two criminals. This requires you to decide whether a and b belong to a same gang.InputThe first line of the input contains a single integer T (1 <= T <= 20), the number of test cases. Then T cases follow. Each test case begins with a line with two integers N and M, followed by M lines each containing one message as described above.OutputFor each message "A [a] [b]" in each case, your program should give the judgment based on the information got before. The answers might be one of "In the same gang.", "In different gangs." and "Not sure yet."Sample Input15 5A 1 2D 1 2A 1 2D 2 4A 1 4Sample OutputNot sure yet.In different gangs.In the same gang.Problem H : The RaceFrom:POJ, 2274DescriptionDuring the Annual Interstellar Competition for Tuned Spaceships, N spaceships will be competing. Each spaceship i is tuned in such a way that it can accelerate in zero time to its maximum speed Vi and remain cruising at that speed. Due to past achievements, each spaceship starts at a starting position Xi, specifying how many kilometers the spaceship is away from the starting line.The race course is infinitely long. Because of the high speeds of the spaceships, the race course goes straight all the time. On that straight course, spaceships can pass one another very easily, without interfering with each other.Many people in the audience have not realized yet that the outcome of the race can be determined in advance. It is your task to show this to them, by telling them how many times spaceships will pass one another, and by predicting the first 10 000 times that spaceships pass in chronological order.You may assume that each spaceship starts at a different position. Furthermore, there will never be more than two spaceships at the same position of the course at any time.InputThe first line of the input specifies the number of spaceshipsN (0 < N <= 250 000) that are competing. Each of the next N lines describe the properties of one spaceship. The i+1th line describes the ith ship with two integers Xi and Vi, representing the starting position and the velocity of the ith spaceship (0 <= Xi <= 1 000 000, 0 < Vi < 100). The spaceships are ordered according to the starting position, i.e. X1 < X2 < . . . < XN. The starting position is the number of kilometers past the starting line where the spaceship starts, and the velocity is given in kilometers per second.OutputThe first line of the output should contain the number of times that spaceships pass one another during the race modulo 1 000 000. By publishing the number of passes only modulo 1 000 000, you can at the same time prove your knowledge of it and don't spoil the party for the less intelligent people in the audience.Each of the subsequent lines should represent one passing, in chronological order. If there would be more than 10 000 passings, only output the first 10 000 passings. If there are less than 10 000 passings, output all passings. Each line should consist of two integers i and j, specifying that spaceship i passes spaceship j. If multiple passings occur at the same time, they have to be sorted by their position on the course. This means that passings taking place closer to the starting line must be listed first. The time of a passing is the time when the two spaceships are at the same position.Sample Input40 22 13 86 3Sample Output23 41 2Problem I : Apple TreeFrom:POJ, 3321DescriptionThere is an apple tree outside of kaka's house. Every autumn, a lot of apples will grow in the tree. Kaka likes apple very much, so he has been carefully nurturing the big apple tree.The tree has N forks which are connected by branches. Kaka numbers the forks by 1 to N and the root is always numbered by 1. Apples will grow on the forks and two apple won't grow on the same fork. kaka wants to know how many apples are there in a sub-tree, for his study of the produce ability of the apple tree.The trouble is that a new apple may grow on an empty fork some time and kaka may pick an apple from the tree for his dessert. Can you help kaka?InputThe first line contains an integer N (N≤ 100,000) , which is the number of the forks in the tree.The following N - 1 lines each contain two integers u and v, which means fork u and fork v are connected by a branch.The next line contains an integer M (M≤ 100,000).The following M lines each contain a message which is either"C x" which means the existence of the apple on fork x has been changed. i.e. if there is an apple on the fork, then Kaka pick it; otherwise a new apple has grown on the empty fork.or"Q x" which means an inquiry for the number of apples in the sub-tree above the fork x, including the apple (if exists) on the fork xNote the tree is full of apples at the beginningOutputFor every inquiry, output the correspond answer per line.Sample Input31 21 33Q 1C 2Q 1Sample Output32Problem J : Starry NightFrom:POJ, 1175DescriptionHigh up in the night sky, the shining stars appear in clusters of various shapes. A cluster is a non-empty group of neighbouring stars, adjacent in horizontal, vertical or diagonal direction. A cluster cannot be a part of a larger cluster.Clusters may be similar. Two clusters are similar if they have the same shape and number of stars, irrespective of their orientation. In general, the number of possible orientations for a cluster is eight, as Figure 1 exemplifies.The night sky is represented by a sky map, which is a two-dimensional matrix of 0's and 1's. A cell contains the digit 1 if it has a star, and the digit 0 otherwise.Given a sky map, mark all the clusters with lower case letters. Similar clusters must be marked with the same letter; non-similar clusters must be marked with different letters. You mark a cluster with a lower case letter by replacing every 1 in the cluster by that lower case letter. The order of allocation of letters depends on the first appearance of different clusters, from top to bottom and from left to right.InputYour program is to read from standard input. The first two lines contain, respectively, the width W and the height H of a sky map. The sky map is given in the following H lines, of W characters each.0 <= W (width of the sky map) <= 1000 <= H (height of the sky map) <= 1000 <= Number of clusters <= 5000 <= Number of non-similar clusters <= 26 (a..z)1 <= Number of stars per cluster <= 160OutputYour program is to write to standard output. The output contains the same map as the input, except that the clusters are marked as described above.Sample Input2315100010000000000100000000111110001111100010110101000000010001000111111000000000101010001011110000011101000100000000000001001011111000000000100000010000000000000000010100000011111001000000001000000100010011111000000011101010101000100000010011010001000000000010001110111110000000001000011100000001000000000100010000100010010100000001110001000111000Sample Outputa000a0000000000b00000000aaaaa000ccccc000d0dd0d0a0000000c000c000dddddd000000000c0b0c000d0dddd00000eee0c000c0000000000000e00e0ccccc000000000b000000e00000000000000000b0f000000ccccc00a00000000f000000c000c00aaaaa0000000ddd0c0b0c0a000a000000b00dd0c000c0000000000g000ddd0ccccc000000000g0000ddd0000000e000000000b000d0000f000e00e0b0000000ddd000f000eee000HintJust to make it clearer, notice that this sample input corresponds to the following picture of the sky.Notice that this sample output corresponds to the following picture.Problem K : Mobile phonesFrom:POJ, 1195DescriptionSuppose that the fourth generation mobile phone base stations in the Tampere area operate as follows. The area is divided into squares. The squares form an S * S matrix with the rows and columns numbered from 0 to S-1. Each square contains a base station. The number of active mobile phones inside a squarecan change because a phone is moved from a square to another or a phone is switched on or off. At times, each base station reports the change in the number of active phones to the main base station along with the row and the column of the matrix.Write a program, which receives these reports and answers queries about the current total number of active mobile phones in any rectangle-shaped area.InputThe input is read from standard input as integers and the answers to the queries are written to standard output as integers. The input is encoded as follows. Each input comes on a separate line, and consists of one instruction integer and a number of parameter integers according to the following table.The values will always be in range, so there is no need to check them. In particular, if A is negative, it can be assumed that it will not reduce the square value below zero. The indexing starts at 0, e.g. for a table of size 4 * 4, we have 0 <= X <= 3 and 0 <= Y <= 3.Table size: 1 * 1 <= S * S <= 1024 * 1024Cell value V at any time: 0 <= V <= 32767Update amount: -32768 <= A <= 32767No of instructions in input: 3 <= U <= 60002Maximum number of phones in the whole table: M= 2^30OutputYour program should not answer anything to lines with an instruction other than 2. If the instruction is 2, then your program is expected to answer the query by writing the answer as a single line containing a single integer to standard output.Sample Input0 41 12 32 0 0 2 21 1 1 21 12 -12 1 1 2 33Sample Output34Problem L : Potted FlowerFrom:POJ, 2750DescriptionThe little cat takes over the management of a new park. There is a large circular statue in the center of the park, surrounded by N pots of flowers. Each potted flower will be assigned to an integer number (possibly negative) denoting how attractive it is. See the following graph as an example:(Positions of potted flowers are assigned to index numbers in the range of 1 ... N. The i-th pot and the (i + 1)-th pot are consecutive for any given i (1 <= i < N), and 1st pot is next to N-th pot in addition.)The board chairman informed the little cat to construct "ONE arc-style cane-chair" for tourists having a rest, and the sum of attractive values of the flowers beside the cane-chair should be as large as possible. You should notice that a cane-chair cannot be a total circle, so the number of flowers beside thecane-chair may be 1, 2, ..., N - 1, but cannot be N. In the above example, if we construct a cane-chair in the position of that red-dashed-arc, we will have the sum of 3+(-2)+1+2=4, which is the largest among all possible constructions.Unluckily, some booted cats always make trouble for the little cat, by changing some potted flowers to others. The intelligence agency of little cat has caught up all the M instruments of booted cats' action. Each instrument is in the form of "A B", which means changing the A-th potted flowered with a new one whose attractive value equals to B. You have to report the new "maximal sum" after each instruction.InputThere will be a single test data in the input. You are given an integer N (4 <= N <= 100000) in the first input line.The second line contains N integers, which are the initial attractive value of each potted flower. The i-th number is for the potted flower on the i-th position.A single integer M (4 <= M <= 100000) in the third input line, and the following M lines each contains an instruction "A B" in the form described above.Restriction: All the attractive values are within [-1000, 1000]. We guarantee the maximal sum will be always a positive integer.OutputFor each instruction, output a single line with the maximum sum of attractive values for the optimum cane-chair.Sample Input53 -2 1 2 -542 -25 -52 -45 -1Sample Output4435。