您的位置:首页 > 编程语言

CodingTrip携程编程大赛-位图像素的颜色

2014-04-11 20:18 344 查看

位图像素的颜色

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 0    Accepted Submission(s): 0


[align=left]Problem Description[/align]

有一个在位图上画出矩形程序,一开始位图都被初始化为白色(RGB颜色表示为R=G=B=255)。该程序能够按照顺序绘出N个矩形。新绘制的矩形能够覆盖位图上原有的颜色。程序执行完毕后,需要查询M个点的颜色,输出这些点的RGB值。

每组数据都是在初始化后开始绘制。

 

 

[align=left]Input[/align]

第一行包含参数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就表示输入结束。

 

 

[align=left]Output[/align]

对于每个用例,按行输出查询的像素的RGB值,每行包含3个整数,分别表示RGB值。

 

 

[align=left]Sample Input[/align]

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

 

 

[align=left]Sample Output[/align]

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
;
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;
}

}


 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  比赛