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

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

WBOY
Release: 2024-04-12 10:31:06
forward
1161 people have browsed it

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>
Copy after login

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!

source:linuxprobe.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template