Scanning lens in the grass of n*m, mention Mo planted k mushrooms, mushroom explosion of great power, Rambo do not want to rush to rush, and the mushroom is invisible. Only one item called the scanning lens can scan the invisible mushroom, so he goes back to the War Academy, buys 2 scanning lenses, and a scanning lens can be scanned (3*3 All the mushrooms in the box, then Rambo can clean off some invisible mushrooms. Q: How many mushrooms can rambo clean up?
Input Description:
The first row of three integers: n,m,k, (1≤n,m≤20,k≤100), n,m represents the size of the grassland; next K lines, two integers per line, x, Y (1≤x≤n,1≤y≤m). A mushroom is planted on behalf of (X, y). A square can grow an infinite number of mushrooms.
Output Description:
Output one line, and output an integer in this line, representing the maximum number of mushrooms that Rambo can clean up.
Solving
Scan the mirror, scan, clean out, the answer is not k?
Unable to understand test instructions
The discussion below explains
A scanning lens can scanall the mushrooms in the (3*3) square, asking the maximum number of mushrooms to be cleaned to find out which of the two-dimensional arrays (3*3) has the most mushrooms in the area. There are two lenses, so the maximum number of mushrooms to be cleaned is the first lens to be cleaned up and the second lens cleaned up (the maximum number of mushrooms to be cleaned is written as a function).
It is important to note that for each square if there is more than one mushroom then one scan can only clean up one mushroom.
This requires us to subtract 1 from the number of mushrooms in the corresponding squares in the two-dimensional array after the first optimal solution is obtained.
1. Violence finds the number of non-empty squares within the first 3*3
2. The number minus 1 in the square
3. Violence to find a second
Such a square is, the non-empty element maximum
ImportJava.util.Scanner; Public classmain{ Public Static voidMain (string[] args) {Scanner in=NewScanner (system.in); while(In.hasnext ()) {intn =In.nextint (); intm =In.nextint (); intK =In.nextint (); if(n<3) n=3; if(m<3) M=3; int[] A =New int[N][m]; for(intI =0;i<k;i++){ intx =In.nextint (); inty =In.nextint (); A[x-1][y-1]++; } intFirst[] =New int[3]; intSecond[] =New int[3]; Scan (A,first); for(inti = first[1];i< First[1] + 3;i++){ for(intj = first[2];j<first[2] + 3;j++){ if(a[i][j]>0) A[i][j]--; }} Scan (A,second); System.out.println (first[0] + second[0]); } } Public Static voidScan (int[] A,int[] arr) { intn =a.length; intm = a[0].length; for(intI =0;i<n-2;i++){ for(intJ =0;j< m-2;j++){ intnum = 0; for(intU = i;u<i+3;u++){ for(intV =j;v<j+3;v++){ if(A[u][v] >0) {num++; } } } if(arr[0]<=num) {arr[0] =num; arr[1] =i; arr[2] =J; } } } }}
NetEase 2016 Research engineer programming problem: Scanning lens