The main topic: there is a stick of length n, this stick is composed of n length of 1 small sticks, of course, due to the time placed long, some small sticks have not been strong, so Yong too want to let six flowers to the wooden
stick into the length of 4 paragraphs, of which there are 3 paragraphs to no firm small sticks, Yong too hope that the length of these 3 pieces of sticks and can be the largest. At the same time, six flowers hope to meet Yong too requirements to let these three sticks can spell a
triangle, ask Meng Meng six flowers have how many kinds of feasible partition scheme.
Problem Solving Ideas:
First find out all the small sticks in the leftmost position L and the rightmost position R, can be determined that one of the paragraph must be [L,r].
then consider the following in two different situations:
1.l=1 or R=n
the remaining three paragraphs are truncated by a whole block of sticks, and we can enumerate the length of the leftmost segment, so that we can get an inequality about the second stick, a little discussion.
2. In addition to 1, the
situation is relatively easy, the enumeration is the left or the right paragraph as a complete paragraph, and then enumerate another segment of the cutting point, judge whether it is legal, if legal to add one to the answer.
time Complexity O (n+m).
hack point: 1. A long long is not opened. 2. The first case is not considered or the first case is wrong. 3. Direct attempt to use O (N2) for violence
#include <iostream> using namespace std;
int main () {int n, m, temp;
while (scanf ("%d%d", &n, &m)! = EOF) {int left = 0x3f3f3f3f, right = 0;
for (int i = 0; i < m; i++) {scanf ("%d", &temp);
left = min (left, temp);
right = max (right, temp);
} int len_l = left-1;
int len_r = N-right;
if (len_l = = 0 && Len_r = = 0) {printf ("0\n");
} else if (len_l! = 0 && Len_r! = 0) {Long Long cnt = 0, ans = 0;
int len_max = max (len_l, Len_r);
int len_min = min (len_l, len_r); for (int i = 1; I <= len_max/2; i++) if (len_l + len_r > 2 * MAX (len_min, Max (i, len_max-i))) {if (i =
= Len_max-i) ans--;
cnt++;
} cout << ans + cnt * 2 << Endl; } else if ((len_l = = 0 && Len_r! = 0) | | (len_l! = 0 && Len_r = = 0))
{Long Long cnt = 0;
int len = len_l + Len_r;
for (int i = 1; I <= (len-1)/2; i++) {len_l = Len-i-(len-1)/2; CNT + = (len-1)/2-len_l + 1;
} cout << cnt << Endl;
}} return 0;
}