This article mainly introduced the Python method to solve the problem of chicken with rabbit cage, analyzes the principle and solution of chicken with rabbit cage, and presents a Python implementation code, very has the reference value, need friends can under reference

in this instance the Python method to solve the problem of chicken with rabbit cage, share to everybody for your reference. Specific analysis is as follows:

description

a cage shut chickens and rabbits (chicken has two legs, the rabbit has four legs, no exceptions). Already know the total number of feet inside the cage son a, ask how many animal cage at least, up to how many animals

input data

line 1 is a test data set number n, followed by n lines of the input. Each set of test data of 1 row, including a positive whole number (32768) a <a.

output requirements

n rows, each row output corresponding to one input. Output are two positive integers, the first one is the least number of animals, the second one is up to the number of animals, two positive integers separated by Spaces. If you don't meet the requirements, the output of 2 0.

input sample

2
3
20
The output sample
0 0
5 to 10

their thinking:

first consider special circumstances, when a is odd, the results are of 0
Second consider even number:
Assume that chicken I, the rabbit j, then a=I + 4 * 2 * j
We require the minimum and maximum I + j
Easy to know I + j=(a - 2 j)/2 when the bigger j I + j is smaller when the smaller the greater the I + j j
Of course we can also simple to think with weight value, and don't need to think about the specific calculation process

python implementation is as follows:

code is as follows:


n=input ()
L=list ()
For k in range (n) :
      InputNum=input ()
      #odd
      If inputNum % 2!=0:
              Min=Max=0
      The else:
      #even
      #min
              J=inputNum/4
              I=inputNum % 4/2
              Min=I + j
      #Max
              Max=inputNum/2
      L +=[(min and Max)]
     
For a, b in l:
      Print a, b

hope described in this article to the Python programming help.

you might be interested in the article:

  • Python implementation method of splicing more photos
  • Python certified encryption to decrypt method
  • Python socket are adopted to simulate the method to realize the TCP communications
  • Python implementation method of automatic email to QQ group members
  • Python port scanning system implementation method
  • Python by zlib compression and decompression of the string method
  • Python implementation kNN algorithm and simple digital identification method
  • Python implementation of the decision tree method
  • Python implementation of naive bayes algorithm method
  • Python implementation in a directory search method of the specified file
  • Python implementation method of network backup automatically download 115


This concludes the body part