wordpress   发布时间:2022-04-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ZOJ Problem Set - 2480 Simplest Task in Windows大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

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
Simplest Task in Windows
Time Limit: 2 Seconds       @H_11_24@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.


@H_944_35@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.


@H_944_35@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.


@H_944_35@Sample Input

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


@H_944_35@Sample Output

0
0
-1

 
方法一:我想的方法
 1 #include <iostream>
 2 #include <cstdio>
 3 using namespace std;
 4 int win[15][4];
 5 int main()
 6 {   int N;
 7     scanf("%d",&N);
 8     while(N>0){
 9             for(int i=0;i<N;i++)
10                 for(int j=0;j<4;j++)
11                 win[i][j]=-1;
12             for(int i=0;i<N;i++){
13                 for(int j=0;j<4;j++){
14                     int temp;
15                     scanf("%d",&temp);
16                     win[i][j]=temp;
17                 }
18             }
19             int M;
20             bool flag=0;
21             scanf("%d",&@H_670_93@m);
22             for(int i=0;i<M;i++){
23                 flag=0;
24                 int cx,cy;
25                 scanf("%d",&cX);
26                 scanf("%d",&cy);
27                 for(int j=N-1;j>=0;j--){
28                     if(win[i][j]==-1)
29                         conTinue;
30                     if(cx<=win[j][2]&&cx>=win[j][0]&&cy<=win[j][3]&&cy>=win[j][1]){
31                         printf("%d\n",j);
32                         flag=1;
33                         break;
34                     }
35                 }
36                 if(!flag) printf("-1\n");
37             }
38             scanf("%d",&N);
39     }
40     return 0;
41 }
1、因为漏写了那个break纠结了蛮久的,所以以后碰到循环都稍微想一想什么时候该停下来
2、因为忘记初始化win数组也纠结了一会,所以以后碰到数组都要记得初始化
3、因为窗口输入顺序是BACk to front,注意逆序寻找窗口
 
方法二:
 1 #include <iostream>
 2 #include <cstdio>
 3 using namespace std;
 4 int win[107][107];
 5 int main()
 6 {   int N;
 7     scanf("%d",&N);
 8     while(N>0){
 9             for(int i=0;i<107;i++){
10                 for(int j=0;j<107;j++)
11                     win[i][j]=-1;
12             }
13             for(int i=0;i<N;i++){
14                     int l,d,r,u;
15                     scanf("%d",&l);
16                     scanf("%d",&d);
17                     scanf("%d",&r);
18                     scanf("%d",&u);
19                 for(int j=l;j<=r;j++){
20                     for(int k=d;k<=u;k++)
21                         win[j][k]=i;
22                 }
23             }
24             int M;
25             bool flag=0;
26             scanf("%d",&@H_670_93@m);
27             for(int i=0;i<M;i++){
28                 flag=0;
29                 int cx,cy;
30                 scanf("%d",&cX);
31                 scanf("%d",&cy);
32                 if(win[cx][cy]!=-1){
33                     printf("%d\n",win[cx][cy]);
34                     flag=1;
35                 }
36                 if(!flag) printf("-1\n");
37             }
38             scanf("%d",&N);
39     }
40     return 0;
41 }

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

大佬总结

以上是大佬教程为你收集整理的ZOJ Problem Set - 2480 Simplest Task in Windows全部内容,希望文章能够帮你解决ZOJ Problem Set - 2480 Simplest Task in Windows所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。