Chicken and rabbit cage

Source: Internet
Author: User

Problem description

A cage is closed with chickens and rabbits (chickens have 2 feet, rabbits have 4 feet, no exceptions). Already know the total number of feet inside the cage A, ask how many animals in the cage, at least how many animals

Input data

Line 1th is the number of groups of test data n, followed by n-line input. Each group of test data accounted for 1 rows, including a positive integer a (a < 32768).

Output requirements

n rows, one input per line of output. The output is two positive integers, the first is the minimum number of animals, the second is the largest number of animals, and two positive integers are separated by a space. If the condition does not meet the requirements, Output 2 0.

Input sample

2
3
20
Output sample
0 0
5 10

Problem Solving Ideas:First consider the special case, when a is odd, the result is 0 followed by an even number: Suppose the chicken I only, Rabbit J only, then a=2*i+4*j we require i+j minimum and maximum easy to know i+j= (A-2J)/2 when J Greater i+j smaller when J smaller The larger the i+j, of course, we can simply use the weight value to think, and do not need to think about the specific computational process Python implementation is as follows:
n=input () L=list () forKinchrange (N): Inputnum=input ()#Odd    ifinputnum%2!=0:min=max=0Else:    #even    #minJ=inputnum/4I=inputnum%4/2min=i+J#MaxMax=inputnum/2L+=[(Min,max)] forA, binchL:PrintA, b

Chicken and rabbit cage

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.