栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

第十三届蓝桥杯大赛软件赛决赛 Java 大学 B 组试题 D: 窗口(暴力求解)

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

第十三届蓝桥杯大赛软件赛决赛 Java 大学 B 组试题 D: 窗口(暴力求解)

时间限制: 3.0s 内存限制: 512.0MB 本题总分:10 分

【问题描述】

在平时使用电脑的过程中,经常会打开各种各样的窗口,各个窗口会在桌 面上重叠,并按照一定的层次关系显示。有的窗口能够看到全部内容,而有的 窗口只能看到局部。

现在给定一组操作桌面窗口的过程序列,请你通过 ASCII 艺术图来绘制最 后桌面的状态。

已知桌面的大小为 N × M,即桌面高度为 N 个像素,宽度为 M 个像素, 其中左上角坐标为 (0, 0),右下角坐标为 (N − 1, M − 1)。

对于窗口的操作有如下 5 种:

1. new 操作 - 打开一个新窗口

new [PID] [top] [left] [height] [width]

如:new 12 20 30 80 100

表示打开一个 PID 为 12 的窗口,窗口左上角的坐标为 (20, 30),该窗口宽 度为 100 个像素,高度为 80 个像素;新创建的窗口,其层级为顶层。

2. move 操作 - 移动一个窗口

move [PID] [vertical] [horizontal]

如: move 12 -5 10

表示将 PID 为 12 的窗口在垂直方向上移动 −5 个像素,在水平方向上移 动 10 个像素。若窗口左上角原位置为 (20, 30),此时则在 (15, 40);移动后的窗 口,其层级为顶层。

3. resize 操作 - 改变窗口大小

resize [PID] [height] [width]

如:resize 12 90 110

表示保持左上角坐标不变的情况下,改变 PID 为 12 的窗口大小,调整为 高度 90 像素,宽度 110 像素;改变大小后的窗口,其层级为顶层。

4. close 操作 - 关闭窗口

close [PID]

如:close 12

表示关闭 PID 为 12 的窗口;

5. active 操作 - 激活窗口

active [PID]

如:active 12

表示激活 PID 为 12 的窗口,此时该窗口的层级被置为顶层。

【输入格式】

第 1 行:2 个正整数 N, M,表示桌面大小; 第 2 行:1 个正整数 K,表示操作序列的长度; 第 3 . . . K + 2 行:每行一个操作,格式见题目描述。

【输出格式】

第 1 . . . N 行:每行 M 个字符,仅包含 ‘.’, ‘+’, ‘-’, ‘|’, ‘ ’ 五种字符。 ‘.’ 表示桌面背景,即该部分未被任何窗口覆盖,‘+’ 表示窗口的四个角,‘-’ 表示窗口的横边, ‘|’ 表示窗口的竖边,‘ ’ 表示窗口内部。

【样例输入】

7 10

8

new 1 0 3 2 5

new 2 4 4 2 5

new 3 3 3 4 6

resize 3 3 6

move 1 0 5

close 2

new 4 1 1 3 5

active 3

【样例输出】

........+-

.+---+..+-

.| |....

.+-+----+.

...| |.

...+----+.

..........

 

 

【评测用例规模与约定】

对于 100% 的数据,1 ≤ N, M ≤ 256, 1 ≤ K ≤ 10000.

输入数据保证:

1. 同一时间不会有两个相同 PID 的窗口存在,可能存在关闭某个 PID 的 窗口后,再新建一个同样 PID 的窗口,PID 的取值范围为 1 ≤ PID ≤ 100000;

2. 同时存在的窗口数量不超过 200 个;

3. 窗口尺寸不会小于 2 × 2,即窗口高度和宽度均不会小于 2,不会大于 N × M;

4. 窗口在移动过程中,可能有部分界面超出桌面显示范围;

5. 所有输入的数值均不超过 ±100000。

6. move resize close 只会对未关闭的窗口操作。   

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException { 
		InputReader in = new InputReader();
		int n = in.nextInt(), m = in.nextInt(), k = in.nextInt();
		List list = new LinkedList();
		Window[] arr = new Window[100005];
		for (int i = 0; i < k; i++) {
			String op = in.next();
			int pid = 0;
			switch (op) {
			case "new":
				pid = in.nextInt();
				arr[pid] = new Window(pid, in.nextInt(), in.nextInt(), in.nextInt(), in.nextInt());
				list.add(0, arr[pid]);
				break;
			case "move":
				pid = in.nextInt();
				list.remove(arr[pid]);
				arr[pid].move(in.nextInt(), in.nextInt());
				list.add(0, arr[pid]);
				break;
			case "resize":
				pid = in.nextInt();
				list.remove(arr[pid]);
				arr[pid].resize(in.nextInt(), in.nextInt());
				list.add(0, arr[pid]);
				break;
			case "close":
				pid = in.nextInt();
				list.remove(arr[pid]);
				break;
			case "active":
				pid = in.nextInt();
				list.remove(arr[pid]);
				list.add(0, arr[pid]);
				break;
			}
		}
		char[][] graph = new char[n][m];
		for (int i = 0; i < n; i++) {
			Arrays.fill(graph[i], '.');
		}
		for (int i = list.size() - 1; i > -1; i--) {
			Window w = list.get(i);
			for (int j = w.top; j < n && j < w.top + w.height; j++) {
				for (int u = w.left; u < m && u < w.left + w.width; u++) {
					if (j == w.top && u == w.left || j == w.top && u == w.left + w.width - 1 || j == w.top + w.height - 1 && u == w.left || j == w.top + w.height - 1 && u == w.left + w.width - 1) {
						graph[j][u] = '+';
					}else if (j == w.top || j == w.top + w.height - 1) {
						graph[j][u] = '-';
					}else if (u == w.left || u == w.left + w.width - 1) {
						graph[j][u] = '|';
					}else {
						graph[j][u] = ' ';
					}
				}
			}
		}
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				System.out.print(graph[i][j]);
			}
			System.out.println();
		}
		
	}
	
}
class Window{
	public int pid;
	public int top;
	public int left;
	public int height;
	public int width;
	public Window(int pid, int top, int left, int height, int width) {
		this.pid = pid;
		this.top = top;
		this.left = left;
		this.height = height;
		this.width = width;
	}
	public void move(int h, int v) {
		this.top += h;
		this.left += v;
	}
	public void resize(int h, int w) {
		this.height = h;
		this.width = w;
	}
}
class InputReader{
	BufferedReader buf;
	StringTokenizer tok;
	public InputReader() {
		buf = new BufferedReader(new InputStreamReader(System.in));
	}
	boolean hasNext() {
		while (tok == null || !tok.hasMoreElements()) {
			try {
				tok = new StringTokenizer(buf.readLine());
			} catch (Exception e) {
				return false;
			}
		}
		return true;
	}
	String next() {
		if (hasNext()) {
			return tok.nextToken();
		}
		return null;
	}
	int nextInt() {
		return Integer.parseInt(next());
	}
	long nextLong(){
		return Long.parseLong(next());
	}
	double nextDouble() {
		return Double.parseDouble(next());
	}
	String nextLine() throws IOException {
		return buf.readLine();
	}
}

 

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/980864.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号