位圖像素的顏色
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 0 Accepted Submission(s): 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]);
}
}
}
}
}