A: (hdu1081)
Test instructions
Sum the largest sub-matrices
Solve:
First, one-dimensional arrays are considered, and the continuous sub-sequences with the largest values can be obtained by O (n) complexity.
In the same vein, the prefix is maintained for each row and then enumerated from the L column to the R column, the L column of each row to the R column can be obtained by prefix and O (1), and then the value between the L column and the R column of each row as an element of the one-dimensional array, O (n) is the answer.
Total complexity: O (n3)
1#include <bits/stdc++.h>2 3 Const intMAXN =133;4 5 intN;6 intMA[MAXN][MAXN];7 8 intMain ()9 {Ten while(~SCANF ("%d", &N)) { One for(inti =1; I <= N; ++i) { Ama[i][0] =0; - for(intj =1; J <= N; ++j) { -scanf"%d", &ma[i][j]); theMA[I][J] + = ma[i][j-1]; - } - } - intres =-0x7fffffff; + for(intL =1; L <= N; ++l) { - for(intR = l; R <= N; ++r) { + intTMP =0, ans =-0x7fffffff; A for(inti =1; I <= N; ++i) { at intEle = Ma[i][r]-ma[i][l-1]; -TMP + =ele; -Ans =Std::max (ans, tmp); - if(TMP <0) { -TMP =0; - } in } -res =Std::max (res, ans); to } + } -printf"%d\n", res); the } *}
View Code
B: (hdu1060)
Test instructions
The leftmost digit of the n^n
Solve:
A = LG (NN) = n * LG (N)
Then 10A = NN, set p to the fractional part of a, then the integer portion of 10p is the answer
C: (hdu1007)
Test instructions
Planar closest point pair
Solve:
This topic is more trickery, the solution is many.
Can be used to rotate the jam, can divide the treatment, can also be ordered two times directly
It is important to think that if two points are planar closest points, there must be no other point in the rectangle with the two points diagonally. According to this idea can be sorted two times, with the distance of adjacent points to maintain the minimum value.
Complexity: O (N*log (n))
D: (hdu4007)
Test instructions
Given n points, the square with the edge length R can be up to how many points (can be on the bounding box)
Solve:
Solution One: You can use the scanning line, to each point, the point for the lower left corner of the structure of a rectangle, then there are 1000 rectangles, to find a rectangular area intersection, the segment tree maintenance interval maximum can be.
Solution Two: First of all points according to the horizontal order, from the left to the right enumeration point, as the rectangle to the left of the horizontal axis, two out of the rectangular frame can be framed in the rightmost point. The difference of the horizontal axis of these points is not greater than r, the coordinates of these points are placed in an array, after sorting the ruler to sweep again.
Both the complexity of the two are: O (N*log (n))
1#include <bits/stdc++.h>2 3 structpoint{4 intx, y;5 BOOL operator< (ConstPoint &tmp)Const6 {7 returnX <tmp.x;8 }9}point[ ++Ten];Ten One A - intN, R; - intt[ ++Ten]; the - intCheckintLintR) - { - intCNT =0; + for(inti = l; I <= R; ++i) -T[++CNT] =point[i].y; +Std::sort (t+1, t+1+CNT); A inti =1, j =1; at intres =0; - intTMP =0; - while(J <=CNT) { - if(T[j]-t[i] <=R) { -++J; -++tmp; in } - Else { to++i; +--tmp; - } theres =Std::max (RES, TMP); * } $ returnRes;Panax Notoginseng } - the intMain () + { A while(~SCANF ("%d%d", &n, &R)) { the for(inti =1; I <= N; ++i) +scanf"%d%d", &point[i].x, &point[i].y); -Std::sort (point+1, point+1+n); $ intres =0; $ for(inti =1; I <= N; ++i) { - intL = i, r =N; - while(L <=r) { the intMID = L + R >>1; - if(point[mid].x > point[i].x +R)WuyiR = Mid-1; the Else -L = mid +1; Wu } -res = Std::max (res, check (i, L-1)); About } $printf"%d\n", res); - } -}
View Code
E: (hdu1176)
Test instructions
There will be n pies falling down in the sky, respectively, at the t moment, X position (0 <= x <= 10), the person starts at 5 position, each moment can move left or right one unit, ask to be able to receive the maximum value of the pie
Solve:
CAKE[T][X] is how many pies fall off at the T-moment x position.
DP[T][X] = max (dp[t-1][x-1], dp[t-1][x], dp[t+1][x]) + cake[t][x];
2015-11-3-training (for 2014th)