Difficulty level: A; programming language: Unlimited; run time limit: 1000ms; run space limit: 51200KB; code length limit: 2000000B |
Question 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 |
Line 1th is the number of groups of test data n, followed by n-line input. 1 rows per set of test data, one positive integer per line (a<32768) |
Output |
The output contains n rows, one input per line, two positive integers, the first being the fewest number of animals, the second being the largest number of animals, and two positive integers separated by a single space If the required answer is not met, the output is two 0. |
Input example |
2 3 20 |
Output example |
0 0 5 10 |
From this we can see immediately, if the total number of feet is odd, then direct output 0 0, because even addition is not surprisingly number.
Next, we can judge: to make the animals at least, it is all off the rabbit (think about why?) To make the most animals, it's all off the chickens. Do you have any questions about this?
#include <iostream>using namespace Std;int a,i,x,m,n;int main () { cin>>a; for (i=0;i<a;i++) { cin>>x; if (x%2==0) { m=x/4; if (x%4!=0) n=1; cout<<m+n<< "; M=X/2; cout<<m; } else cout<<0<< ' <<0; cout<<endl; } return 0;}
c++8002011752 Chicken and rabbit cage