位图像素的颜色(携程编程大赛第二场2014-4-11)

位图像素的颜色

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) {
		// TODO Auto-generated method stub
    Scanner sc = new Scanner(System.in);
     while(true){
    	 int n = sc.nextInt();
    	 int m = sc.nextInt();
    	 if(n==0&&m==0)break;
    	 E [] e = new E[n];
    	 for(int i=0;i<n;i++)
    		 e[i] = new E(255, 255, 255);
 
    	 int x,y;
    	 
    	 for(int i=0; i<n; i++){
    		 e[i] = new E();
    		 e[i].x1 = sc.nextInt();
    		 e[i].y1 = sc.nextInt();
    		 e[i].x2 = sc.nextInt();
    		 e[i].y2 = sc.nextInt();
    		 e[i].r  = sc.nextInt();
    		 e[i].g  = sc.nextInt();
    		 e[i].b  = sc.nextInt();
    	 } whi:while(m-->0){
    		 x = sc.nextInt();
    		 y = sc.nextInt();
    		 for(int i=n-1;i>=0;i--){//倒着查找
    			 if(x>=e[i].x1&&x<=e[i].x2 && y>=e[i].y1&&y<=e[i].y2){
    				 System.out.println(e[i].r+" "+e[i].g+" "+e[i].b);
    				 continue whi;
    			 }
    		 }System.out.println("255 255 255");
    	 }
     }
	}
}
class E{
    int r,g,b;
	int x1,x2,y1,y2;
	public E(int r,int g,int b ){
		this.b = b;
		this.g = g;
		this.r = r;
	}E(){}
}

最挫的写法!超内存!

import java.util.Arrays;
import java.util.Scanner;

public class Main {
 
    public static void main(String[] args) {
        // TODO Auto-generated method stub
    Scanner sc = new Scanner(System.in);
     while(true){
         int n = sc.nextInt();
         int m = sc.nextInt();
         if(n==0&&m==0)break;
         String [][]x = new String[2002][2002];
         for(int i=0;i<1000;i++){
             Arrays.fill(x[i], "255");
         }
        int x1,x2,y1,y2,r,g,b;
        String s;
         for(int i=0;i<n;i++){
             x1 = sc.nextInt();
             y1 = sc.nextInt();
             x2 = sc.nextInt();
             y2 = sc.nextInt();
             r  = sc.nextInt();
             g  = sc.nextInt();
             b  = sc.nextInt();
             s = r+"="+g+"="+b;
             for(int j=x1;j<=x2;j++){
                 for(int k=y1;k<=y2;k++){
                     x[j][k] = s;
                 }
             }
         }
        while(m-->0){
            int a = sc.nextInt();
            int e = sc.nextInt();
            if(x[a][e].equals("255")){
                System.out.println("255 255 255");
            }else{
                String []as = x[a][e].split("=");
                System.out.println(as[0]+" "+as[1]+" "+as[2]);
            }
        }
     }
    }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值