HDU 4486 pen counts

Source: Internet
Author: User
Pen counts

Time Limit: 2000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 246 accepted submission (s): 144

Problem descriptionchicken farmer Xiaoyan Is getting three new chickens, Lucy, Charlie and CC. she wants to build a chicken pen so that each chicken has its own, unobstructed view of the countryside. the pen will have three straight sides;
This will give each chicken its own side so it can pace back and forth without interfering with the other chickens. xiaoyan finds a roll of chicken wire (fencing) in the barn that is exactly n feet long. she wants to figure out how many different ways she
Can make a three sided chicken pen such that each side is an integral number of feet, and she uses the entire roll of fence.
Different rotations of the same pen are the same, however, reflections of a pen may be different (see below ).

Inputthe first line of input contains a single integer p, (1 <= P <= 1000), which is the number of data sets that follow. each data set shoshould be processed identically and independently.

Each data set consists of a single line of input. it contains the data set number, K, and the length of the roll of fence, N, (3 <=n <= 10000 ).

Outputfor each data set there is a single line of output. it contains the data set number, K, followed by a single space which is then followed by an integer which is the total number of different three-sided chicken pen submissions
That can be made using the entire roll of fence.

Sample Input

 
51 32 113 124 1005 9999

Sample output

 
1 12 53 44 3925 4165834

Sourcegreater New York 2012
 

Recommendliuyiding This question involves some knowledge about triangles. Question: The perimeter of the triangle. Ask how many sides you can create as an integer triangle. If a triangle can be obtained from a vertex of another triangle, the two triangles are regarded as one. Ideas: First, summarize the triangle knowledge. Set the triangle perimeter to Len. L3> = L2> = L1. Sum of two sides> third side. So the value range of the longest side in a triangle is Len/3 rounded up <= L3 <Len/2 rounded up. Rest = len-l3. The value range of the second edge is Rest/2 is rounded down to <L2 <= L3. For an isosceles triangle, the maximum value of its bottom edge length <(LEN + 1)/2. Therefore, given a perimeter, you can determine the number of equi-waist or equi-edge triangles. Therefore, the number of triangles can be determined for each longest side. For details, seeCode:

# Include <iostream> # include <stdio. h> using namespace STD; int main () {int Len, rest, L3, durl2, P, Cas, ans; scanf ("% d", & P ); while (p --) {scanf ("% d", & CAS, & Len); ans = 0; For (l3 = (LEN + 2)/3; l3 <(LEN + 1)/2; L3 ++) // enumerate the length of the longest side {rest = len-l3; // The remaining length durl2 = L3-(rest-1) /2; // The value range of the second edge ans + = 2 * durl2; // two if (! (Rest & 1) // It can be an isosceles triangle ANS-= 1; ANS-= 1;} If (LEN % 3 = 0) // It can be composed of equi-edge ans + = 1; printf ("% d \ n", Cas, ANS);} 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.