标签:
试题编号: 201403-2
时间限制: 1.0s
内存限制: 256.0MB
1 package ccf_test2014_03; 2 3 import java.util.Scanner; 4 5 public class Window { 6 7 private static int N; 8 9 private static int M; 10 11 12 13 public static void main(String[] args) { 14 15 Scanner input = new Scanner(System.in); 16 17 N = input.nextInt(); 18 19 M = input.nextInt(); 20 21 22 int[][]page = new int[N + 1][4]; 23 24 int [][] screen = new int[2560][1440]; 25 26 for(int i = 1; i <= N; i++){ 27 28 int x1 = input.nextInt(); 29 30 int y1 = input.nextInt(); 31 32 int x2 = input.nextInt(); 33 34 int y2 = input.nextInt(); 35 36 page[i][0] = x1; 37 38 page[i][1] = y1; 39 40 page[i][2] = x2; 41 42 page[i][3] = y2; 43 44 for(int p = x1; p <= x2; p++){ 45 46 for(int q = y1; q <= y2; q++){ 47 48 screen[p][q] = i; 49 } 50 } 51 52 53 54 } 55 for(int i = 0; i < M; i++){ 56 57 int x = input.nextInt(); 58 59 int y = input.nextInt(); 60 61 int num = screen[x][y]; 62 63 if(num == 0){ 64 65 System.out.println("IGNORED"); 66 67 }else{ 68 69 System.out.println(num); 70 71 int x1 = page[num][0]; 72 73 int y1 = page[num][1]; 74 75 int x2 = page[num][2]; 76 77 int y2 = page[num][3]; 78 79 for(int p = x1; p <= x2; p++){ 80 81 for(int q = y1; q <= y2; q++){ 82 83 screen[p][q] = num; 84 } 85 } 86 } 87 88 } 89 90 } 91 92 }
实现标准代码(c++):
1 #include <iostream> 2 3 using namespace std; 4 5 int screen[2560][1440]; 6 7 int main(){ 8 int n,m; 9 cin>>n>>m; 10 int page[n+1][4]; 11 for(int i=1;i<=n;i++) 12 { 13 int x1,x2,y1,y2; 14 cin>>x1>>y1>>x2>>y2; 15 page[i][0]=x1; 16 page[i][1]=y1; 17 page[i][2]=x2; 18 page[i][3]=y2; 19 for(int p=x1;p<=x2;p++) 20 for(int q=y1;q<=y2;q++) 21 screen[p][q] = i; 22 } 23 for(int i=0;i<m;i++) 24 { 25 int x,y; 26 cin>>x>>y; 27 int num = screen[x][y]; 28 if(num == 0) 29 { 30 cout<<"IGNORED"<<endl; 31 } 32 else 33 { 34 cout<<num<<endl; 35 int x1(page[num][0]),y1(page[num][1]),x2(page[num][2]),y2(page[num][3]); 36 for(int p=x1;p<=x2;p++) 37 for(int q=y1;q<=y2;q++) 38 screen[p][q] = num; 39 } 40 } 41 return 0; 42 }
我的实现代码(java):
1 package ccf_test2014_03; 2 3 import java.util.Scanner; 4 5 public class Window2 { 6 7 private static int N; 8 9 private static int M; 10 11 12 13 public static void main(String[] args) { 14 15 Scanner input = new Scanner(System.in); 16 17 N = input.nextInt(); 18 19 M = input.nextInt(); 20 21 input.nextLine(); 22 23 int[][]a = new int[N][5]; 24 25 int[][]b = new int[M][2]; 26 27 int []prior = new int[N]; 28 29 for(int i = 0; i < N; i++){ 30 31 a[i][0] = input.nextInt(); 32 33 a[i][1] = input.nextInt(); 34 35 a[i][2] = input.nextInt(); 36 37 a[i][3] = input.nextInt(); 38 39 input.nextLine(); 40 41 prior[i] = i; 42 } 43 44 for(int i = 0; i < M; i++){ 45 46 b[i][0] = input.nextInt(); 47 48 b[i][1] = input.nextInt(); 49 50 input.nextLine(); 51 52 } 53 54 int [] temp = new int[11]; 55 56 int k = 0; 57 58 int max = 0; 59 60 int it = 0; 61 62 for(int i = 0; i < M; i++){ 63 64 for(int j = 0; j < N - 1; j++){ 65 66 boolean condition = (b[i][0] >=a[j][0])&&(b[i][1] >=a[j][1])&&(b[i][0] <=a[j][2])&&(b[i][1] <=a[j][3]); 67 68 if(condition){ 69 70 temp[k++] = j; 71 72 } 73 74 } 75 76 if(k == 0){ 77 78 System.out.println("IGNORED"); 79 }else if(k == 1){ 80 81 for(int j = 0 ; j < N; j++){ 82 83 if(j == temp[0]){ 84 85 prior[j]= N - 1; 86 }else{ 87 88 prior[j]--; 89 } 90 } 91 92 System.out.println(temp[0]+1); 93 94 }else{ 95 96 for(int j = 0 ; j < k; j++){ 97 98 if(prior[temp[j]] > max){ 99 100 max = prior[temp[j]]; 101 it = j; 102 } 103 } 104 System.out.println(temp[it]+1); 105 } 106 k= 0; 107 108 } 109 110 } 111 112 }
三个代码顺序运行结果:
标签:
原文地址:http://www.cnblogs.com/haimishasha/p/5351437.html