Simplest Task in Windows

Time Limit: 2 Seconds      Memory Limit: 65536 KB

A typical windows platform may have several windows on the desktop. A user's operation may be as simple as a single click of the mouse. In the implementation of such a windows platform, one of the simplest tasks would be deciding which window had been clicked.

Given a serial of windows, for each mouse click, decide which window had been clicked. Please notice that windows may overlap, and the window on top would receive the click rather than others. And, we consider a window to be clicked even if the mouse is just on its edge/corner. For the sake of simplicity, we assume that a window will not be activated to the top by any click.

Input

The first part of input is a serial of windows. First an integer N (1 <= N <= 10) is given, indicating the number of windows. Then N lines follow, each containing four integers, x1, y1, x2, y2, (x1 < x2, y1 < y2) the coordinates of the upper-left and lower-right corners of a window. The windows are given in back-to-front order. N=0 signals the end of input.

The second part of input is a serial of mouse clicks. First an integer M (1 <= M <= 50) is given, indicating the number of mouse clicks. Then M lines follow, each containing two integers, x and y, the coordinates of a mouse click.

Output

For each mouse click in the input, output a single line containing the index (starting from 0) of the window which receives the click. If there is no such window, output "-1" in a line instead.

Sample Input

1
0 0 5 5
3
4 1
5 1
6 1
0

Sample Output

0
0
-1

 
方法一:我想的方法
 #include <iostream>
#include <cstdio>
using namespace std;
int win[][];
int main()
{ int N;
scanf("%d",&N);
while(N>){
for(int i=;i<N;i++)
for(int j=;j<;j++)
win[i][j]=-;
for(int i=;i<N;i++){
for(int j=;j<;j++){
int temp;
scanf("%d",&temp);
win[i][j]=temp;
}
}
int M;
bool flag=;
scanf("%d",&M);
for(int i=;i<M;i++){
flag=;
int cx,cy;
scanf("%d",&cx);
scanf("%d",&cy);
for(int j=N-;j>=;j--){
if(win[i][j]==-)
continue;
if(cx<=win[j][]&&cx>=win[j][]&&cy<=win[j][]&&cy>=win[j][]){
printf("%d\n",j);
flag=;
break;
}
}
if(!flag) printf("-1\n");
}
scanf("%d",&N);
}
return ;
}
1、因为漏写了那个break纠结了蛮久的,所以以后碰到循环都稍微想一想什么时候该停下来
2、因为忘记初始化win数组也纠结了一会,所以以后碰到数组都要记得初始化
3、因为窗口输入顺序是back to front,注意逆序寻找窗口
 
方法二:
 #include <iostream>
#include <cstdio>
using namespace std;
int win[][];
int main()
{ int N;
scanf("%d",&N);
while(N>){
for(int i=;i<;i++){
for(int j=;j<;j++)
win[i][j]=-;
}
for(int i=;i<N;i++){
int l,d,r,u;
scanf("%d",&l);
scanf("%d",&d);
scanf("%d",&r);
scanf("%d",&u);
for(int j=l;j<=r;j++){
for(int k=d;k<=u;k++)
win[j][k]=i;
}
}
int M;
bool flag=;
scanf("%d",&M);
for(int i=;i<M;i++){
flag=;
int cx,cy;
scanf("%d",&cx);
scanf("%d",&cy);
if(win[cx][cy]!=-){
printf("%d\n",win[cx][cy]);
flag=;
}
if(!flag) printf("-1\n");
}
scanf("%d",&N);
}
return ;
}

根据别人的思路打的,这个思路也不错,用二维数组模拟一块屏幕,但是因为题目没有提及coordinate的xy取值范围,所以win的大小其实不好拿捏,但是这个107能AC

ZOJ 2480 - Simplest Task in Windows的更多相关文章

  1. ZOJ 2969 Easy Task

    E - Easy Task Description Calculating the derivation of a polynomial is an easy task. Given a functi ...

  2. 微软BI 之SSIS 系列 - 使用 Script Task 访问非 Windows 验证下的 SMTP 服务器发送邮件

    原文:微软BI 之SSIS 系列 - 使用 Script Task 访问非 Windows 验证下的 SMTP 服务器发送邮件 开篇介绍 大多数情况下我们的 SSIS 包都会配置在 SQL Agent ...

  3. NetBeans GUI tests on Jenkins + Windows (转)

    from http://forgetfulprogrammer.wordpress.com/tag/interact-with-desktop/ Running NetBeans applicatio ...

  4. Windows Phone Silverlight 8.1 apps

    The Windows Phone Silverlight 8.1 app model gives Windows Phone 8 developers access to some of the n ...

  5. windows提权基础大全

    Not many people talk about serious Windows privilege escalation which is a shame. I think the reason ...

  6. windows快捷命令修炼

    Description Windows Key combination Open/Close the Start Menu Windows key Open the Action center. Wi ...

  7. Linux常见问题及解决方案

    问题一: 删除Linux 的烦恼(没出现系统选择菜单只出现"grub": 问题描述: 安装了Linux.WinXP双系统,采用Grub引导系统.在XP下通过格式化磁盘(非法操作)删 ...

  8. word20161225

    Waiting for Call / 等待呼叫 wallpaper / 墙纸 WAN, wide area network / 广域网 warning level / 警告级别 Web folder ...

  9. (C#) 调用执行批处理文件

    Task:  在Windows的Service里面定时的调用执行一个批处理文件. private ApplicationOutput RunCommandOnPC(string executableP ...

随机推荐

  1. 学习web的第二天

    之前因为技能大赛的原因,导致我这门课没有上.其实上学期是开Dreamweaver网页制作的课程的,所以老师讲的很快.我就利用课后时间去补漏,今天讲了HTML标签:1.标题标签<h1>~&l ...

  2. SuperMap iObject入门开发系列之五管线属性查询

    本文是一位好友“托马斯”授权给我来发表的,介绍都是他的研究成果,在此,非常感谢. 管线属性查询功能针对单一管线图层进行特定的条件查询,然后将查询结果输出为列表,并添加点位闪烁功能,例如查询污水管线中, ...

  3. MSSQL 更改表结构

    更改表结构: alter TABLE 表1 ALTER COLUMN 列名1 NCHAR(40)

  4. SpringBoot整合RabbitMQ-整合演示

    本系列是学习SpringBoot整合RabbitMQ的练手,包含服务安装,RabbitMQ整合SpringBoot2.x,消息可靠性投递实现等三篇博客. 学习路径:https://www.imooc. ...

  5. 福利:1H1G2M云服务器限时15元/月,买2送1,一年加6个月只要180元

    平时看文章做测试只能用虚拟机的有福了,现在腾迅做活动,1H1G2M的服务器一个月只需要15元,买2送1,最多可以送6个月. 这个比之前1H1G1M10元一月的要好一些 购买地址

  6. [Swift-2019力扣杯春季决赛]2. 按字典序排列最小的等效字符串

    给出长度相同的两个字符串:A 和 B,其中 A[i] 和 B[i] 是一组等价字符.举个例子,如果 A = "abc" 且 B = "cde",那么就有 'a' ...

  7. BTrace 问题辅助排查工具使用手册

    BTrace是调试神器,可以通过自己编写的脚本,获取应用的一切调用信息.而不需要重启应用! Btrace 项目源码信息(你行你上~) 项目地址:http://github.com/btraceio/b ...

  8. 9. VIM 系列 - YouCompleteMe 实现代码补全

    目录 环境准备 插件安装 环境准备 $ sudo apt install build-essential cmake python3-dev python-dev $ sudo apt install ...

  9. Hadoop系列004-Hadoop运行模式(上)

    title: Hadoop系列004-Hadoop运行模式(上) date: 2018-11-20 14:27:00 updated: 2018-11-20 14:27:00 categories: ...

  10. .NET Core微服务之基于Consul实现服务治理

    Tip: 此篇已加入.NET Core微服务基础系列文章索引 一.Consul基础介绍 Consul是HashiCorp公司推出的开源工具,用于实现分布式系统的服务发现与配置.与其他分布式服务注册与发 ...