[BZOJ1600] [Usaco2008 OCT] Building Fences

Source: Internet
Author: User

Description

Diligent farmer John wants to build a fence around them to keep the cows locked. He had a board of N (4<=n<=2500) that he wanted to cut into 4 pieces. These four pieces of planks can be any length as long as farmer John can surround them with a reasonable quadrilateral. He was able to cut out how many different kinds of reasonable solutions. Note: * As long as the cutting point of the board is different as a different scheme (like the whole arrangement), do not worry about another special case, go ahead. * Fence size is greater than 0.

* The output guarantees that the answer is within the Longint range. * The whole piece of wood must be run out.

Input

* First line: a number n

Output

* First line: Reasonable total number of programs

Sample Input6
Sample Output6
The output is detailed:
Farmer John was able to cut out all the cases for: (1, 1, 1,3); (1, 1, 2, 2); (1, 1, 3, 1); (1, 2, 1, 2); (1, 2, 2, 1); (1, 3, 1, 1);
(2, 1, 1, 2); (2, 1, 2, 1); (2, 2, 1, 1); or (3, 1, 1, 1).
The following four species-(1, 1, 1, 3), (1, 1, 3, 1), (1, 3, 1, 1), and (3,1, 1, 1)-cannot form a quadrilateral.
HINTSource

Qualifying Tournament

Solution

If the shortest three of the four line segments is longer than the longest segment, spicy will certainly make up the quadrilateral.

Enumerates the length of the first two edges, and the value range of the last two edges can be calculated.

1#include <bits/stdc++.h>2 using namespacestd;3 intMain ()4 {5     intN, a, b, ans =0;6CIN >>N;7      for(inti =1; I <= (n-1) >>1; i++)8          for(intj =1; J <= (N-1) >>1; J + +)9         {TenA = MIN (n-1) >>1, N-i-J-1); Oneb = N-i-J-A; AAns + = max (A-B +1,0); -         } -cout << ans <<Endl; the     return 0; -}
View Code

[BZOJ1600] [Usaco2008 OCT] Building Fences

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.