Home  >  Article  >  System Tutorial  >  Mathematical Olympiad's "Cow Eating Grass Problem" C++ Implementation

Mathematical Olympiad's "Cow Eating Grass Problem" C++ Implementation

WBOY
WBOYforward
2024-04-12 10:31:061054browse

Mathematical Olympiads Cow Eating Grass Problem C++ Implementation

Questions are as follows:

There is a pasture. The grass on the pasture grows at a constant rate every day. This pasture can feed 15 cows for 20 days, or 20 cows for 10 days. Then, the amount of new grass in this pasture every day can provide How many cows can be eaten in a day?

The ideas for solving mathematical problems are as follows:

Assuming that a cow eats one serving of grass every day, then 15 cows eating grass for 20 days is: 15 X 20 = 300 servings. 20 cows eating grass for 10 days is: 20 X 10 = 200 servings.

The former is based on the original grass, plus 20 days of new grass. The latter is based on the original grass, plus 10 days of new grass.

300-200=100 copies, 20-10=10 days.

It means that 100 portions of grass grow in 10 days, then 10 portions of grass grow every day, which is enough for 10 cows to eat for one day.

The answer is that the amount of new grass in this pasture can be eaten by 10 cows for a day.

Continue to think: 10 cows eat newly grown grass every day, and the remaining cows eat the original grass, we can get:

Original grass: (15-10)X 20 = 100 parts or (20-10)X 10 = 100 parts

It is interesting to convert mathematical problems into code implementation. Since the children are new to some simple C codes, I wrote the simplest version.

The following uses C language programming to implement this problem:
int main()
{
    int m1,n1,m2,n2;//mi为牛的数量,ni为mi对应的吃草天数。 
    cin>>m1>>n1>>m2>>n2;
    int x=(m1*n1-m2*n2)/(n1-n2);
    cout
<p> If you need to reprint, please indicate the source: http://www.cnblogs.com/wongyi/</p>

The above is the detailed content of Mathematical Olympiad's "Cow Eating Grass Problem" C++ Implementation. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:linuxprobe.com. If there is any infringement, please contact admin@php.cn delete
Previous article:Why study algorithms?Next article:Why study algorithms?