Algorithm notes 001-- chickens and rabbits with cage

A cage off the chicken and rabbits (two feet chickens, rabbits have four legs, without exception).

Already we know the total number of feet inside the cage a, cage and asked how many animals there are at least, up to the number of animals?

————————————————————————————————————————

This is the fourth grade of primary school on the solution of the equation did question, then also learned a number of ways:

Let chicken lift one foot into a "foot stand" so that the rabbit legs to stand up and turn into a rabbit, the rabbit is the difference between the head and feet of only a few;

Solution of the equation set number of chicken or rabbit is x, is another animal (head number -x), then the answer for solving the equation;

Even that can list and drawing ......

 

#include <cstdio>
int main ()
{
    int Jiao, Mmin, Mmax;
    the printf (. "enter the number of pins of the \ n-");
    Scanf ( "% D", & Jiao);
    IF (! Jiao% 2 = 0)
        printf ( "input error !!! \ n-");
    the else
    {
        Mmin = (Jiao. 3 +) /. 4;
        Mmax = Jiao / 2;
        printf ( "minimum number of animals:% d \ n Maximum number of animals:% d \ n ", Mmin, Mmax);
    }
    return 0;
}

 

Assuming that the number of inputs is 10 feet, and that at least two rabbits is a chicken, is up to five chickens;

In this sense the question is rounded up to the completion of the operation;

mmin = (jiao + 3) / 4;

This completes the line of rounding up operation, that is:

Results = (dividend divisor + -1) + divisor;

So that you can achieve it -

(For example, rounding up is 10/2 = 5, 10/3 = 4 so)

(This computer idiot do not know more than a few 01-plus-one on this idea)

According to this idea can also be rounded write code (plus 0.5)

————————————————————————————————————————

Sahua ~ ~ ~

Chicken rabbit cage with the end of it ~ ~ ~

Guess you like

Origin www.cnblogs.com/jun-ruo-sui-nian/p/suijun_001.html