Home > System Tutorial > LINUX > Chicken and rabbit in the same cage - detailed explanation of the algorithm

Chicken and rabbit in the same cage - detailed explanation of the algorithm

WBOY
Release: 2024-04-03 09:55:01
forward
725 people have browsed it

Chicken and rabbit in the same cage - detailed explanation of the algorithm

Let’s talk about the importance of algorithms with the help of teacher Kaifu Li’s words: “Algorithms are one of the most important cornerstones in the field of computer science, but they have been ignored by some domestic programmers. Many students Seeing that some companies require a variety of programming languages ​​when recruiting, there is a misunderstanding that learning computers means learning various programming languages, or that learning the latest languages, technologies, and standards is the best way to pave the way. In fact, everyone I have been misled by these companies. Although programming languages ​​should be learned, it is more important to learn computer algorithms and theories, because computer algorithms and theories are more important, because computer languages ​​and development platforms are changing with each passing day, but those algorithms and theories remain the same. For example, data structures, algorithms, compilation principles, computer architecture, relational database principles, etc. On the "Kaifu Student Network", a student vividly compared these basic courses to "internal skills", which combines new languages, technologies , the standard is compared to "external skills". People who follow the trend all day long only know the moves in the end. Without skills, it is impossible to become a master."

Today we will take a look at the classic chicken and rabbit problem.

The question is as follows: There is a classic "chicken and rabbit in the same cage" problem in mathematics. It is known that there are 30 heads and 90 feet in the cage. How many chickens and rabbits are there?

Mathematical problem solving implementation:

Suppose there are X chickens and Y rabbits. According to the meaning of the question, two linear equations of two variables are obtained:

X Y =30

2*X 4*Y=90

Then the solution is X=15, Y=15.

The following programming is implemented:

#include 
using namespace std;
int main()
{
    int head,foot;
    cout>head>>foot;
    int X,Y;
    Y=(foot-2*head)/2;
    X=head-Y;
    cout
Copy after login

The above is the detailed content of Chicken and rabbit in the same cage - detailed explanation of the algorithm. 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