HDU 5203 Rikka with wood sticks

Source: Internet
Author: User

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;
 }


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.