CCF the window (_1403_2_window.java) of the true title of calendar year reference answer

Source: Internet
Author: User

CCF the window (_1403_2_window.java) of the true title of calendar year reference answer

Problem Description:

Question number: 201403-2
Question Name: Window
Time limit: 1.0s
Memory Limit: 256.0MB
Problem Description: problem description in a graphics operating system, there are N windows, each with a rectangular area that is parallel to the axes. The point on the boundary of the window also belongs to the window. There is a hierarchy of differences between windows, and in areas where more than one window overlaps, only the contents of the window at the top level are displayed.
When you click on a point on the screen, you select the topmost window in the clicked position, and the window is moved to the top of all windows, and the remaining windows are in the same order. If you click on a location that does not belong to any of the windows, the system ignores your click.
Now we want you to write a program that simulates the process of clicking a window. The first line entered in the input format has two positive integers, that is, N and M. (1≤N≤10,1≤M≤10)
The next n lines give the position of the N window in the order from lowest to topmost. Each row contains four non-negative integers x 1, y 1, x 2, and Y 2, representing a pair of vertex coordinates for the window (x 1, y 1) and (x 2, y 2). Guarantee X 1 < x 2,y 1 2.
The next M row contains two non-negative integers x, y, which represents the coordinates of a mouse click. The x, y coordinates of all points and vertices of the rectangle that are involved in the topic are not more than 2559 and 1439 respectively. Output format output includes M row, each row represents the result of a mouse click. If the mouse clicks Select a window, the number of the window is output (the window is numbered from 1 to N in the order in which it was entered), and if not, the output is "ignored" (without double quotes).   Sample Input 3 4
0 0 4 4
1 1 5 5
2 2 6 6
1 1
0 0
4 4
0 5 Example Output 2
1
1
Ignored sample description The first-click position belongs to both the 1th and 2nd windows, but since the 2nd window is above, it is selected and placed on the top floor.
The second click Position only belongs to window 1th, so this click selects the window and places it on the top. The hierarchical relationship of the three windows now is exactly the opposite of the initial state. The
Third Click Position also falls within the range of three windows, but it is selected because the 1th window is now at the top level. The
last clicked (0, 5) does not belong to any window.

Reference code:

Import Java.util.Scanner;
		public class _1403_2_window {public static void main (string[] args) {Scanner input = new Scanner (system.in);
		int I, j = 1, k, current = 0,flag=0;
		int n = input.nextint ();
		int m = Input.nextint ();
		window[] window = new Window[n + 1];
		window[] Click = new WINDOW[M]; /* The location of the record window and the ID of the window (the first entered window is at the bottom, so I start with N) * * for (i = n; i > 0; i--) {window[i] = new Window (input.nextint
			), Input.nextint (), Input.nextint (), Input.nextint ());			
		Window[i].setid (n-i + 1);
		/* * Record the location of the point you want to click for (i = 0; i < m i++) {Click[i] = new Window (Input.nextint (), Input.nextint ()); * * Find Window * * for (i = 0; i < m i++) {for (j=1;j<n+1;j++) {if (window[j].getx1 () <= Click[i].getx (
						) && window[j].getx2 () >= click[i].getx () && window[j].gety1 () <= click[i].gety () 
					&& window[j].gety2 () >= click[i].gety ()) {flag=j; Current = Window[j].getid (); Record the target window ID window[0] = window[j]; Record the target window//* Put the window before the target window to a position, the window after the target window without moving the (k = j; k > 1; k--) {Window[k] = Window[k
					-1];	} window[1] = window[0];  Move the target window to the top level break;
				Found a window to jump out, do not need to continue looking, because the target window relative to the other window is the front of the else{flag=0;
				} if (flag!= 0) {System.out.println (current);
				else {System.out.println ("ignored");
	} input.close ();

	}/* Customize a window class */class Window {private int x1, y1, x2, y2, x, y, id;
	public int getX1 () {return x1;
	The public void setX1 (int x1) {this.x1 = x1;
	public int getY1 () {return y1;
	The public void setY1 (int y1) {this.y1 = y1;
	public int getX2 () {return x2;
	The public void setX2 (int x2) {this.x2 = x2;
	public int getY2 () {return y2;
	The public void setY2 (int y2) {this.y2 = y2;
	public int GetX () {return x;
	public void SetX (int x) {this.x = x;
	public int GetY () {return y; } public VoID sety (int y) {this.y = y;
	public int getId () {return id;
	The public void setId (int id) {this.id = ID;
		Public Window () {super ();
		TODO auto-generated Constructor stub} public Window (int x1, int y1, int x2, int y2) {super ();
		this.x1 = x1;
		This.y1 = y1;
		this.x2 = x2;
	This.y2 = y2;
		The public Window (int x, int y) {super ();
		this.x = x;
	This.y = y;
		public Window (int id) {super ();

	This.id = ID; }	
}


Submission is available by:



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.