CodingTrip攜程編程大賽-位圖像素的顏色

位圖像素的顏色

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0


Problem Description
有一個在位圖上畫出矩形程序,一開始位圖都被初始化爲白色(RGB顏色表示爲R=G=B=255)。該程序能夠按照順序繪出N個矩形。新繪製的矩形能夠覆蓋位圖上原有的顏色。程序執行完畢後,需要查詢M個點的顏色,輸出這些點的RGB值。 每組數據都是在初始化後開始繪製。
 


 

Input
第一行包含參數N和M,分別表示矩形個數和需要查詢的像素個數(1 ≤N, M≤ 1000 ); 剩下N行每行包含7個參數x1, y1, x2, y2, r, g, b,表示繪製一個(x1,y1),(x2,y2)爲頂點的矩形,填充顏色爲RGB(r, g, b),其中x1≤x2, y1≤y2數據在整型範圍;0≤ r,g,b ≤ 255; 最後M行分別包含參數X和Y,表示需要查詢的像素位置。 如果某行N=M=0就表示輸入結束。
 


 

Output
對於每個用例,按行輸出查詢的像素的RGB值,每行包含3個整數,分別表示RGB值。
 


 

Sample Input
1 2 0 0 2 3 127 196 200 1 2 3 0 2 3 8 16 32 64 0 255 128 8 48 32 64 255 0 0 12 47 13 48 14 64 0 0
 


 

Sample Output
127 196 200 255 255 255 0 255 128 255 0 0 255 0 0

 

import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		Scanner input=new Scanner(System.in);
		while(true){
			int n=input.nextInt();
			int m=input.nextInt();
			if(n==0&&m==0)
				break;
			Node node[]=new Node[n];
			for(int i=0;i<n;i++){
				int x1=input.nextInt();
				int y1=input.nextInt();
				int x2=input.nextInt();
				int y2=input.nextInt();
				int r=input.nextInt();
				int g=input.nextInt();
				int b=input.nextInt();
				node[i]=new Node(x1,y1,x2,y2,r,g,b);
			}
			for(int i=0;i<m;i++){
				int x=input.nextInt();
				int y=input.nextInt();
				boolean ok=true;
				for(int j=n-1;j>=0;j--){
					if(x>=node[j].x1&&x<=node[j].x2&&y>=node[j].y1&&y<=node[j].y2){
						System.out.println(node[j].R+" "+node[j].G+" "+node[j].B);
						ok=false;
						break;
					}
				}
				if(ok){
					System.out.println("255 255 255");
				}
			}
		}
	}
}
class Node{
	int x1,y1,x2,y2;
	int R,G,B;

	public Node(int x1, int y1, int x2, int y2, int r, int g, int b) {
		this.x1 = x1;
		this.y1 = y1;
		this.x2 = x2;
		this.y2 = y2;
		R = r;
		G = g;
		B = b;
	}

	public int getR() {
		return R;
	}

	public void setR(int r) {
		R = r;
	}

	public int getG() {
		return G;
	}

	public void setG(int g) {
		G = g;
	}

	public int getB() {
		return B;
	}

	public void setB(int b) {
		B = b;
	}

	public int getX1() {
		return x1;
	}

	public void setX1(int x1) {
		this.x1 = x1;
	}

	public int getY1() {
		return y1;
	}

	public void setY1(int y1) {
		this.y1 = y1;
	}

	public int getX2() {
		return x2;
	}

	public void setX2(int x2) {
		this.x2 = x2;
	}

	public int getY2() {
		return y2;
	}

	public void setY2(int y2) {
		this.y2 = y2;
	}
	
}


 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章