上海交通大学2005-2007年计算机上机真题附答案(3)

本站小编 免费考研网/2016-08-04


respectively. There will be one machine gun shooting through each opening.
Here we assume that a bullet is so powerful that it can run across any
distance and destroy a blockhouse on its way. On the other hand, a wall is
so strongly built that can stop the bullets.

11

The goal is to place as many blockhouses in a city as possible so that no
two can destroy each other. A configuration of blockhouses is legal
provided that no two blockhouses are on the same horizontal row or vertical
column in a map unless there is at least one wall separating them. In this
problem we will consider small square cities (at most 4x4) that contain
walls through which bullets cannot run through.

The following image shows five pictures of the same board. The first
picture is the empty board, the second and third pictures show legal
configurations, and the fourth and fifth pictures show illegal
configurations. For this board, the maximum number of blockhouses in a
legal configuration is 5; the second picture shows one way to do it, but
there are several other ways.

□■□□
●■□●
□■●□
□■□□
□■□□
□□□□
□●□□
□●□□
●□□●
□□●□
■■□□
■■●□
■■●□
■■□□
■■□□
□□□□
●□□□
●□□□
□□□□
□□●□


Your task is to write a program that, given a description of a map,
calculates the maximum number of blockhouses that can be placed in the city
in a legal configuration.


The input file contains one or more map descriptions, followed by a line
containing the number 0 that signals the end of the file. Each map
description begins with a line containing a positive integer n that is the
size of the city; n will be at most 4. The next n lines each describe one
row of the map, with a '.' indicating an open space and an uppercase 'X'
indicating a wall. There are no spaces in the input file.



For each test case, output one line containing the maximum number of
blockhouses that can be placed in the city in a legal configuration.

Sample input:

4
.X..
....
XX..
....

2
XX
.X

3
.X.

X.X
.X.

3
...
.XX
.XX

4
....
....
....


....

0

Sample output:

5
1
5
2
4

Trees are fundamental in many branches of computer science. Current state-of-t
he art parallel computers such as Thinking Machines' CM-5 are based on fat tre
es. Quad- and octal-trees are fundamental to many algorithms in computer graph
ics.

This problem involves building and traversing binary trees.

Given a sequence of binary trees, you are to write a program that prints a lev
el-order traversal of each tree. In this problem each node of a binary tree co
ntains a positive integer and all binary trees have fewer than 256 nodes.

In a level-order traversal of a tree, the data in all nodes at a given level a
re 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.
参考试题2:
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 a
nd R indicates a right branch. In the tree diagrammed above, the node containi
ng 13 is specified by (13,RL), and the node containing 2 is specified by (2,LL
R). The root node is specified by (5,) where the empty string indicates the pa
th from the root to itself. A binary tree is considered to be completely speci
fied if every node on all root-to-node paths in the tree is given a value exac
tly once.
Input
The input is a sequence of binary trees specified as described above. Each tre
e in a sequence consists of several pairs (n,s) as described above separated b
y 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-fi

相关话题/计算机

  • 领限时大额优惠券,享本站正版考研考试资料!
    大额优惠券
    优惠券领取后72小时内有效,10万种最新考研考试考证类电子打印资料任你选。涵盖全国500余所院校考研专业课、200多种职业资格考试、1100多种经典教材,产品类型包含电子书、题库、全套资料以及视频,无论您是考研复习、考证刷题,还是考前冲刺等,不同类型的产品可满足您学习上的不同需求。 ...
    本站小编 Free壹佰分学习网 2022-09-19
  • 2008年上海交通大学计算机考研复试上机试题
    本站小编 免费考研网 2016-08-04
  • 2016年东北大学计算机专业基础考研真题(完整版)
    2016年东北大学计算机专业基础考研真 题(完整版)凯程首发 一、简答 1、 循环语句while和dowhile的区别。 2、 有static声明的局部变量和自由变量的区别。 3、 根据 4、Int (*p)[4]和int *p[4]的区别 二、写出程序运行的结果 有一个是用指针作函数参数,实现数据的交换 有一个是a[9]={1, ...
    本站小编 免费考研网 2016-07-31
  • 2009-2015年计算机组成原理考研大题
    43.(8 分)某计算机的 CPU 主频为 500MHz,CPI 为 5(即执行每条指令平均需 5 个时钟周期)。假定某外设的数据传输率为 0.5MB/s,采用中断方式与主机进行数据传送,以 32 位为传输单位,对应的中断服务程序包含 18 条指令,中断服务的其他开销相当于 2 条指 令的执行时间。请回答下列问题,要求给出计算过程。 (1) ...
    本站小编 免费考研网 2016-07-31
  • 2009-2015年计算机组成原理考研选择题
    11.冯诺依曼计算机中指令和数据均以二进制形式存放在存储器中,CPU 区分它们的依据是 。 A.指令操作码的译码结果 B.指令和数据的寻址方式 C.指令周期的不同阶段 D.指令和数据所在的存储单元 11.C。考查指令的执行过程。 通常完成一条指令可分为取指阶段和执行 ...
    本站小编 免费考研网 2016-07-31
  • 计算机科学与技术考研报考注意事项
    计算机科学与技术考研报考注意事项 近几年由于专业的热门和考研竞争的异常激烈,因此国内一些重点院校的计算机专业硕士生入学分数都非常高,这种情况在一些重点院校特别突出。报考计算机专业研究生的朋友一定要充分地认清这种现实情况,做好充分的准备,思想上要树立考试胜利的信心,并且做好刻苦复习 ...
    本站小编 免费考研网 2016-07-27
  • 计算机科学与技术专业解析
    计算机科学与技术专业解析  一、培养目标   本专业培养和造就适应现代化建设需要。德智体全面发展、基础扎实、知识面宽、能力强、素质高具有创新精神,系统掌握计算机硬件、软件的基本理论与应用基本技能,具有较强的实践能力,能在企事业单位、政府机关、行政管理部门从事计算机技术研究和应用 ...
    本站小编 免费考研网 2016-07-27
  • 计算机软件与理论就业方向与就业前景
    计算机软件与理论就业方向与就业前景 计算机科学与技术专业介绍   计算机科学与技术是研究计算机的设计与制造,以及信息获取、表示、存储、处理、传输和利用等方面的理论、原则、方法和技术的学科。它包括科学与工程技术两方面,两者互为作用,高度融合,这是计算机科学与技术学科的突出特点。计 ...
    本站小编 免费考研网 2016-07-27
  • 计算机应用技术就业方向与就业前景
    计算机应用技术就业方向与就业前景 计算机应用技术专业介绍   计算机应用技术是计算机科学与技术专业下设的一个二级学科,某些院校可以授予理学学位,在此针对工学学位进行解析。本学科主要研究计算机各种应用中具有共性的理论、技术和方法,以及各种前沿性、创新性的计算机应用。   计算 ...
    本站小编 免费考研网 2016-07-27
  • 计算机系统结构就业方向与就业前景
    计算机系统结构就业方向与就业前景 计算机系统结构专业介绍   计算机系统结构是计算机科学与技术专业下设的二级学科。某些院校可以授予理学学位,在此针对工学学位进行解析。计算机系统结构是计算机的的机器语言程序员或编译程序编写者所看到的外特性。所谓外特性,就是计算机的概念性结构和功能 ...
    本站小编 免费考研网 2016-07-27
  • 北京邮电大学计算机学院简介
    北京邮电大学计算机学院简介 北京邮电大学计算机学院源于1985年9月成立的北京邮电大学计算机工程系,后经多次机构调整和更名,2008年9月由计算机科学与技术专业、网络工程专业、智能科学与技术专业和信息安全专业合并形成了现在的计算机学院。   计算机学院是全校规模大、综合实力强的 ...
    本站小编 免费考研网 2016-07-27