- Total Time Limit: 1000ms Memory Limit: 65536kB
- describe
-
Chickens and rabbits are kept in a cage (chickens have 2 feet, rabbits have 4 feet, no exceptions). Knowing the total number of feet a in the cage, ask how many animals there are at least in the cage and how many animals there are at most.
- enter
- One line, a positive integer a (a < 32768).
- output
-
A line containing two positive integers, the first is the minimum number of animals, the second is the maximum number of animals, and the two positive integers are separated by a space.
If there is no answer that meets the requirements, output two 0s separated by a space.
- sample input
-
20
- Sample output
-
5 10
Solution: If a is a multiple of 4, obviously there are at least a/4 animals and at most a/2 animals. If a is a multiple of 2 but not a multiple of 4, there are at least a/4+1 animals and at most a/2. 0 0 otherwise.
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <vector> #include <set> #include <map> using namespace std; intmain() { int a; cin>>a; int minx=32768,maxx=0; if(a%4==0){ minx=a/4; maxx=a/2; printf("%d %d\n",minx,maxx); }else if(a%2==0&&a%4!=0){ minx=a/4+1; maxx=a/2; printf("%d %d\n",minx,maxx); }else{ printf("0 0\n"); } return 0; }