解题思路:
整体思路就是去除中间繁琐的变换状态,记录最终窗口优先级并绘制。
详细看注释就行了
注意事项:
参考代码:
import java.io.*;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
public class _2022_4窗口 {
static int inf = 0x3f3f3f3f;
static BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
static StreamTokenizer st = new StreamTokenizer(bf);
static PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));
public static class window{
int top;
int l;
int h;
int w;
//最终窗口优先级
int pior;
public window(int top, int l, int h, int w, int pior) {
this.top = top;
this.l = l;
this.h = h;
this.w = w;
this.pior = pior;
}
}
static int n;
static int m;
static int k;
//索引当作窗口PID来记录窗口改变窗口
static window [] arr = new window[100000 + 5];
//结果图
static char ans[][];
//根据优先级从小到大排列后的窗口顺序.
static window [] aarr;
public static void main(String[] args) throws IOException {
String [] tmp1 = bf.readLine().split(" ");
n = Integer.parseInt(tmp1[0]);
m = Integer.parseInt(tmp1[1]);
k = Integer.parseInt(bf.readLine());
ans = new char[n][m];
for (int i = 0; i < n; i++){
Arrays.fill(ans[i], '.');
}
//用于存储窗口PID之后不至于完全遍历arr数组
Queue<Integer> q = new LinkedList<>();
int li = 0;
int lj = 0;
int ri = 0;
int rj = 0;
//用于记录窗口个数方便设置aarr数组大小
int num = 0;
//用于设置窗口优先级大小,确保靠后操作的窗口优先级最大
int mpt = 1;
for (int i = 0; i < k; i++){
String s = bf.readLine();
String [] tmp = s.split(" ");
if (!q.contains(Integer.parseInt(tmp[1]))) {
q.offer(Integer.parseInt(tmp[1]));
}
switch (tmp[0]){
case "new":
num++;
arr[Integer.parseInt(tmp[1])] = new window(Integer.parseInt(tmp[2]),Integer.parseInt(tmp[3]),Integer.parseInt(tmp[4]),Integer.parseInt(tmp[5]), ++mpt);
break;
case "move" :
arr[Integer.parseInt(tmp[1])].top += Integer.parseInt(tmp[2]);
arr[Integer.parseInt(tmp[1])].l += Integer.parseInt(tmp[3]);
arr[Integer.parseInt(tmp[1])].pior = ++mpt;
break;
case "resize" :
arr[Integer.parseInt(tmp[1])].h = Integer.parseInt(tmp[2]);
arr[Integer.parseInt(tmp[1])].w = Integer.parseInt(tmp[3]);
arr[Integer.parseInt(tmp[1])].pior = ++mpt;
break;
case "close" :
arr[Integer.parseInt(tmp[1])].pior = 0;
break;
case "active":
arr[Integer.parseInt(tmp[1])].pior = ++mpt;
break;
}
}
bf.close();
aarr = new window[num];
//记录完所有数据后PID就没有用了,只考虑优先级就行了
int tmp = 0;
while(!q.isEmpty()){
aarr[tmp] = arr[q.poll()];
tmp++;
}
//因为条件说存在的窗口不超过200所以为了保证稳定性采用冒泡排序
for (int end = num - 1; end > 0; end--){
for (int begin = 0; begin < end; begin++){
if (aarr[begin].pior > aarr[begin + 1].pior){
window temp = aarr[begin];
aarr[begin] = aarr[begin + 1];
aarr[begin + 1] = temp;
}
}
}
//绘制窗口
for(int i = 0; i < num; i++){
if (aarr[i].pior != 0){
li = aarr[i].top;
lj = aarr[i].l;
ri = li + aarr[i].h - 1;
rj = lj + aarr[i].w - 1;
drow(li, lj, ri, rj);
}
}
//用来测试答案的
// BufferedWriter out = new BufferedWriter(new FileWriter("11.txt"));
// for (int i= 0; i< n; i++){
// for (int j = 0; j < m ;j++){
// out.write(ans[i][j]);
// }
// out.write("\r\n");
//
// }
// out.flush();
for (int i= 0; i< n; i++){
for (int j = 0; j < m ;j++){
System.out.print(ans[i][j]);
}
System.out.println();
}
}
public static void drow(int li, int lj, int ri, int rj){
// 确保能够绘制
if (ri < li ){
li ^= ri;
ri ^= li;
li ^= ri;
}
if (rj < lj){
rj ^= lj;
lj ^= rj;
rj ^= lj;
}
for (int i = li; i <= ri; i++){
for (int j = lj; j <= rj; j++){
if( i < n && j < m && i >= 0 && j >= 0){
if (i == li){
if (j == lj || j == rj){
ans[i][j] = '+';
}else{
ans[i][j] = '-';
}
}else if(i == ri){
if (j == lj || j == rj){
ans[i][j] = '+';
}else {
ans[i][j] = '-';
}
}else if(j == lj || j == rj){
ans[i][j] = '|';
}else {
ans[i][j] = ' ';
}
}
}
}
}
}
0.0分
2 人评分
C语言程序设计教程(第三版)课后习题6.1 (C语言代码)浏览:481 |
C语言程序设计教程(第三版)课后习题5.6 (C语言代码)浏览:909 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:699 |
C语言训练-求函数值 (C语言代码)浏览:600 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:723 |
C语言程序设计教程(第三版)课后习题8.8 (C语言代码)浏览:672 |
1035 题解浏览:875 |
C语言程序设计教程(第三版)课后习题9.3 (C语言代码)浏览:650 |
陶陶摘苹果2 (C语言代码)浏览:650 |
链表数据求和操作 (C语言代码)浏览:1035 |