Split Windows

Description

The Dotty Software Company makes software that is displayed on inexpensive text based terminals. One application for this system has a main window that can be subdivided into further subwindows. Your task is to take a description of the screen layout after a sequence of window splits and draw the minimum sized window grid that is consistent with the description.
In this problem we will concentrate on the boundaries of windows, so all the characters inside of windows will be left blank. Each window that is not further subdivided has a label. Each label is a distinct uppercase letter. For a text terminal the boundaries of windows must be drawn with characters, chosen as follows: A capital letter label is placed in the upper left-hand corner of each undivided window. Asterisks,'*', appear in corners of windows where there is not a label. Dashes, '-', appear on upper and lower boundaries where there are not corners. Vertical bars, '|', appear on side boundaries where there are not corners.

For example, the sequence of splits below would generate Window 1: Initially there could be an application window labeled M, that is split next into left and right subwindows, adding label R, and the left subwindow is split into top and bottom subwindows, adding the label C.

For each pattern of splits there is a binary tree of characters that can describe it. The window splitting and tree structures are described together, building up from the simplest cases.

1. A window may be an undivided rectangle. Such a window has a capital letter as label. The tree for the window contains just the label.

2. A window may either be split into left and right subwindows or into top and bottom subwindows, and the corresponding trees have as root the boundary character for the split: a vertical line '|' or a horizontal dash '-' respectively. The root has left and right subtrees corresponding to the top and bottom or left and right subwindows respectively.

Tree 1, above, and Trees 2-4, below, would be consistent with Windows 1-4. Note that Tree 4 contains Trees 2 and 3.

The trees may be more succinctly expressed via a preorder traversal:

1. The preorder traversal of a tree with just one node (containing a letter) is that letter.

2. The preorder traversal of a tree with a left and a right subtree is the character from the root of the tree ('-' or '|') followed by the preorder traversal of the left subtree, and then the preorder traversal of the right subtree.

The preorder traversals for Trees 1 through 4 are

|-MCR -|-ABC-D|E-FG -P-|Q|RST |-|-ABC-D|E-FG-P-|Q|RST

Each undivided window must have space for at least one character inside. Hence each tree of splits will be associated with a minimum window size. Windows 1-4 are minimum sized windows for Trees 1-4. Each window illustrates the fact that even in a minimum sized window, not all undivided windows contain only one character.

Consider Tree 4 and Window 4. The main window is split into a left window with Tree 2 and right window with Tree 3. The left window is like Window 2, but the right window is not just like Window 3. The heights of left and right subwindows must match, so the right window must be stretched.

The stretching rule depends on a definition of the size of windows. For dimension calculations it is easiest to imagine that a window contains its interior and a half character wide boundary on all sides, so the total dimensions of a window are one more than the dimensions of the interior. Hence the minimum dimensions of a window are 2 by 2, since a window must contain one character inside, and we add one for the boundary. This definition also means that the sum of the widths of left and right subwindows is the width of their enclosing window. The sum of the heights of top and bottom subwindows is the height of their enclosing window.

The right window in Window 4 must be stretched to match the height 10 of the left window. The right window is split into a top with tree P having minimum height 2 and a bottom with tree -|Q|RST having minimum height 4. The rule for the dimensions in the stretched window is that the heights of the subwindows expand in proportion to their minimum heights, if possible. Some symbols may help here: Let D = 10 be the height of the combined stretched window. We want to determine D1 and D2, the stretched heights of the top and bottom subwindow. Call the corresponding minimum dimensions d = 6, d1 = 2, and d2 = 4. If the window were expanded from a total height d to D in proportion, we would have D1 = d1*(D/d) = 2*(10/6) = 3.333...and D2 = d2*(D/d) = 6.666.... Since the results are not integers we increase D1 to 4 and decrease D2 to 6.

There is a similar calculation for the bottom window with tree -|Q|RST. It is further subdivided into a top with tree |Q|RS and a bottom with tree T, each having minimum height 2 = d1 = d2. The heights need to add up to D = 6, so they are increased proportionally to D1 = D2 = 2*(6/4) = 3 (exact integers).

The final dimensions of an enclosing window are always determined before the final dimensions of its subwindows. In this example only heights needed to be apportioned. If all horizontal and vertical splits were interchanged in this example, producing a tree -|-|ABC|D-E|FG|P|-Q-RST, then widths would be apportioned correspondingly, as shown in the third part of the sample output below. If the proportion calculations do not work out to integers, it is always the top or left subwindow whose dimension is increased to the next integer.
Input

The first line of input contains one integer, which is the total number of preorder traversals describing window structures. This line is followed by one line for each preorder traversal. Each preorder traversal will contain appropriate dividers '|' and '-' and from 1 to 26 uppercase letters.
Output

For each preorder traversal, print the number of the preorder traversal on one line followed by the minimum sized window grid that the traversal could represent.
Sample Input

3
|-MCR
|-|-ABC-D|E-FG-P-|Q|RST
-|-|ABC|D-E|FG|P|-Q-RST
Sample Output

1
M-R-*
| | |
C-* |
| | |
--*
2
A-C-P-----*
| | | |
B-* | |
| | | |
D-*-Q-R-S-*
| | | | |
E-F-* | | |
| | T-*-*-*
| G-* |
| | | |
--*-----*
3
A-B-D-E---*
| | | | |
C-*-* F-G-*
| | | | |
P---Q-*T*-*
| | | |
| R--* |
| | | |
| S--* |
| | | |
-----*--*

2个回答

html2pdf导出，windows下正常，linux下乱吗

Problem Description Your current task is to make a ground plan for a residential building located in HZXJHS. So you must determine a way to split the floor building with walls to make apartments in the shape of a rectangle. Each built wall must be paralled to the building's sides. The floor is represented in the ground plan as a large rectangle with dimensions n×m, where each apartment is a smaller rectangle with dimensions a×b located inside. For each apartment, its dimensions can be different from each other. The number a and b must be integers. Additionally, the apartments must completely cover the floor without one 1×1 square located on (x,y). The apartments must not intersect, but they can touch. For this example, this is a sample of n=2,m=3,x=2,y=2. To prevent darkness indoors, the apartments must have windows. Therefore, each apartment must share its at least one side with the edge of the rectangle representing the floor so it is possible to place a window. Your boss XXY wants to minimize the maximum areas of all apartments, now it's your turn to tell him the answer. Input There are at most 10000 testcases. For each testcase, only four space-separated integers, n,m,x,y(1≤n,m≤108,n×m>1,1≤x≤n,1≤y≤m). Output For each testcase, print only one interger, representing the answer. Sample Input 2 3 2 2 3 3 1 1 Sample Output 1 2
python爬虫爬取斗图啦上的图片，打开爬取的图片显示图片错误
![图片说明](https://img-ask.csdn.net/upload/201908/03/1564803739_452406.png) ![图片说明](https://img-ask.csdn.net/upload/201908/03/1564803394_897302.png) import requests,re,os from bs4 import BeautifulSoup def get_url(url): headers={ 'User_Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36', 'Referrer':url } res = requests.get(url,headers=headers) text = res.text soup = BeautifulSoup(text,'lxml') divs = soup.find('div',class_='page-content text-center') a_s = divs.find_all('a',attrs={'class': 'col-xs-6 col-sm-3'}) for a in a_s: #print(a) herf = a['href'] img = a.find('img') print(img) #获取最内层标签方法如下 if a.img['class']==['gif']: pass else: alt = a.img['alt'] alt = re.sub(r'[，@?？!！:。]','',alt) #print(alt) data = a.img['data-original'] print(data) datastr = '.'+data.split('.')[-1] filename = alt + datastr #print(filename) #print(os.getcwd()) if os.path.exists(os.getcwd() + "\斗图啦\\"+filename): print('文件已经存在') else: filename = os.getcwd() + "\斗图啦\\"+filename print(filename) with open(filename,'w') as fp: fp.write(data) def main(): if os.path.exists(os.getcwd()+'\斗图啦\\'): print('文件夹已存在') else: os.mkdir(os.getcwd() + "\斗图啦\\") #for x in range(1,101): # url = 'http://www.doutula.com/photo/list/?page=%d' %x # get_url(url) url = 'http://www.doutula.com/photo/list/?page=1' get_url(url) if __name__ == '__main__': main()  
theano 运行报错 安装了MingGW依然不行

python3.5错误'module' object is not callable
wpf做如何做可以上下拖动Y轴坐标的折线图 用WPFVisifire.Charts做的不能拖动

C#：未将对象引用设置到对象的实例 (System.NullReferenceException)
![图片说明](https://img-ask.csdn.net/upload/201501/27/1422348462_454037.png) 代码如下： using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using System.Windows.Forms; namespace ConsoleExamples { static class Program { /// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] static void Main(string[] args) { Console.Write("请输入x和y(例如12,15),然后按回车键:"); string s = Console.ReadLine(); string[] a = s.Split(','); int x = int.Parse(a[0]); int y = int.Parse(a[1]); int z = x * y; Console.WriteLine("x*y={0}", z); Console.WriteLine("请按任意键结束程序。"); Console.ReadKey(); } } }
C# 为什么ReportViewer做的报表个别电脑出现不显示的情况？

Linux(服务器编程):15---两种高效的事件处理模式（reactor模式、proactor模式）

C语言魔塔游戏

Python爬虫爬取淘宝，京东商品信息

Java工作4年来应聘要16K最后没要,细节如下。。。

2020年，冯唐49岁：我给20、30岁IT职场年轻人的建议

##1、骇客帝国(1999) 概念：在线/离线，递归，循环，矩阵等 剧情简介： 不久的将来，网络黑客尼奥对这个看似正常的现实世界产生了怀疑。 他结识了黑客崔妮蒂，并见到了黑客组织的首领墨菲斯。 墨菲斯告诉他，现实世界其实是由一个名叫“母体”的计算机人工智能系统控制，人们就像他们饲养的动物，没有自由和思想，而尼奥就是能够拯救人类的救世主。 可是，救赎之路从来都不会一帆风顺，到底哪里才是真实的世界？
Python绘图，圣诞树，花，爱心 | Turtle篇

CPU对每个程序员来说，是个既熟悉又陌生的东西？ 如果你只知道CPU是中央处理器的话，那可能对你并没有什么用，那么作为程序员的我们，必须要搞懂的就是CPU这家伙是如何运行的，尤其要搞懂它里面的寄存器是怎么一回事，因为这将让你从底层明白程序的运行机制。 随我一起，来好好认识下CPU这货吧 把CPU掰开来看 对于CPU来说，我们首先就要搞明白它是怎么回事，也就是它的内部构造，当然，CPU那么牛的一个东

2020年1月17日，国家统计局发布了2019年国民经济报告，报告中指出我国人口突破14亿。 猪哥的朋友圈被14亿人口刷屏，但是很多人并没有看到我国复杂的人口问题：老龄化、男女比例失衡、生育率下降、人口红利下降等。 今天我们就来分析一下我们国家的人口数据吧！ 一、背景 1.人口突破14亿 2020年1月17日，国家统计局发布了 2019年国民经济报告 ，报告中指出：年末中国大陆总人口（包括31个
2019年除夕夜的有感而发

2020年的1月，我辞掉了我的第一份工作

By 超神经场景描述：昨天 2 月 3 日，是大部分城市号召远程工作的第一天，全国有接近 2 亿人在家开始远程办公，钉钉上也有超过 1000 万家企业活跃起来。关键词：十一出行 人脸...
Java基础知识点梳理
Java基础知识点梳理 摘要： 虽然已经在实际工作中经常与java打交道，但是一直没系统地对java这门语言进行梳理和总结，掌握的知识也比较零散。恰好利用这段时间重新认识下java，并对一些常见的语法和知识点做个总结与回顾，一方面为了加深印象，方便后面查阅，一方面为了学好java打下基础。 Java简介 java语言于1995年正式推出，最开始被命名为Oak语言，由James Gosling（詹姆
2020年全新Java学习路线图，含配套视频，学完即为中级Java程序员！！

B 站上有哪些很好的学习资源?