Topic link
1. The coordinate value is larger, so the discretization coordinates
2. The absolute value of the coordinates does not exceed 10^9, indicating that there may be negative numbers, so convert all coordinate movements to positive numbers (plus 10^9)
3. Mat[i][j], the Representation (0,0) (I, J) is the number of points within the vertex rectangle including the boundary.
4. Enumerates the upper and lower bounds of the rectangle, and then selects the left and right edges. For the left and right edges of the defined left-hand boundary, assume that the R3 on the bottom of the following image is Ieft, and the L3 is OK, then the number is:
L1 + L2 + L3-(R1+R2) + R3.
In order to have the most points on a rectangle that is L3 to the right boundary, the value of r3-(R1+R2) should be maximized.
So, enumerate right boundary J, maintain the maximum value of the r3-(R1+R2) on the left side of J, as long as O (n) can determine the answer.
5. It should be noted that all points may be in the same line, so give the horizontal and the right coordinates add another point
Code:
#include <cstdio> #include <cstring> #include <vector> #include <algorithm> #include <iostr
Eam> using namespace std;
const int MAXN = 110;
const int ADD = 1E9+10;
int n;
int arr[maxn][2];
int MAT[MAXN][MAXN];
int X[MAXN], y[maxn], row, col;
inline int Findid (int* A, int len, int x) {return Lower_bound (A, A+len, x)-a+1;
} inline void input () {row = 1, col = 1;
X[0] = y[0] = 0;
for (int i=0; i<n; ++i) {scanf ("%d%d", &arr[i][0], &arr[i][1]);
x[row++] = arr[i][0] + = ADD;
y[col++] = arr[i][1] + = ADD;
Sort (X, x+row);
row = Unique (X, X+row)-X;
Sort (Y, y+col);
Col = unique (Y, y+col)-y;
Memset (Mat, 0, sizeof (MAT));
for (int i=0; i<n; ++i) {int a = Findid (X, Row, arr[i][0]);
int b = Findid (Y, col, Arr[i][1]);
MAT[A][B] = 1;
for (int i=1; i<=row; ++i) { for (int j=1; j<=col; ++j) mat[i][j] + = mat[i][j-1]+mat[i-1][j]-mat[i-1][j-1];
} inline int solve () {int ans = 1;
Enum upper bound for (int up=1; up<row; ++up) {for (int down=up+1; down<=row; ++down) {
int maxx = mat[down][1]-mat[up-1][1]; for (int i=2; i<=col; ++i) {int right = Mat[down][i]-mat[down-1][i] + mat[ Up][i]-mat[up-1][i] + mat[down-1][i]-mat[up][i]-(mat[down-1][i-1
]-mat[up][i-1]);
ans = max (ans, right+maxx);
int tmp = Mat[down][i]-mat[up-1][i]-(mat[down][i-1]-mat[up-1][i-1]);
TMP-= Mat[down][i]-mat[down-1][i] + mat[up][i]-mat[up-1][i];
if (tmp > Maxx) maxx=tmp; }} return ans;
int main () {int cas=1;
while (~SCANF ("%d", &n) && N) {input ();
printf ("Case%d:%d\n", cas++, Solve ());
return 0; }
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/