Time Limit: 1000 ms Memory Limit: 50 MB
Total Submission: 10 Submission Accepted: 4
Judge By Case
Description
在当今流行的操作系统中,我们要对许许多多的窗口进行操作,屏幕上的每个窗口都是
由许多单位为 1 的小方块构成的矩形窗,较晚打开的窗口会将一些早期打开的窗口覆盖。我
们可以用鼠标单击一个窗口的右上角的小方块将该窗口关闭,前提是该窗口的右上角的小方
块必须是看得见的。
写一个程序计算一下如果我们要关闭最早打开的那个窗口,最少需要按几下鼠标(关闭
窗口的方法只能靠点击该窗口右上角的小方块实现)
Input
第一行, 一个整数 N,表示窗口的总数,其中 1≤N≤100;
在接下来的 N 行中每一行都有 4 个用空格隔开的整数 R1、 S1、 R2、 S2,其中 1≤R1≤R2≤
10000, 1≤S1≤S2≤10000。 R1, S1 为窗口的左上角坐标, R2、 S2 为窗口的右下角坐标,窗口
打开的次序就是数据给出的次序。
Output
仅一行,包含一个整数表示关闭第一个窗口需要的鼠标最少点击几次。
Sample Input
OriginalTransformed
3
3 1 6 4
1 2 4 6
2 3 5 5
3[EOL]
3[SP]1[SP]6[SP]4[EOL]
1[SP]2[SP]4[SP]6[EOL]
2[SP]3[SP]5[SP]5[EOF]
Sample Output
OriginalTransformed
3
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<iostream>
#include<algorithm>
//#define DEBUG
const int maxn = 150, INF = 1e9 + 1;
struct window{
int r1, s1, r2, s2;
bool flag;
}windows[maxn];
int n,ans=0;
using namespace std;
int judge(int x);
void turn_off(int x);
int main() {
#ifdef DEBUG
freopen("Text.txt", "r", stdin);
#endif // DEBUG
scanf("%d", &n);
int i, j;
for (i = 0; i < n; i++) {
scanf("%d %d %d %d", &windows[i].r1, &windows[i].s1, &windows[i].r2, &windows[i].s2);
windows[i].flag = 1;
}
turn_off(0);
printf("%d\n", ans);
return 0;
}
void turn_off(int x) {
int id;
while (id=judge(x)) {
turn_off(id);
}
ans++;
windows[x].flag = 0;
return;
}
int judge(int x) {
for (int i = x + 1; i < n; i++) {
if (windows[i].r1 <= windows[x].r1&&windows[i].s1 <= windows[x].s2
&& windows[i].r2 >= windows[x].r1&&windows[i].s2 >= windows[x].s2&&windows[i].flag==1)
return i;
}
return 0;
}