牧场上有一片青草,每天都生长得一样快。这片青草供给10头牛吃,可以吃22天,或者供给16头牛吃,可以吃10天,期间一直有草生长。如果供给25头牛吃,可以吃多少天?
时间: 2023-05-23 14:05:06 浏览: 85
设这片青草每天生长的长度为x,它的初始长度为L。
则根据题意,对于22天供给10头牛的情况,有:
L + 22x = 10 × 22
化简可得:
L + 22x = 220
同理,对于16头牛10天的情况,有:
L + 10x = 16 × 10
化简可得:
L + 10x = 160
解以上两个方程,可得:
x = 2,L = 176
即这片青草每天生长2cm,初始长度为176cm。
现在要求25头牛吃这片青草可以吃多少天,设为n,则有:
(176 + 2n) ÷ 25 = n
化简可得:
n = 440 ÷ 23
约等于 19.13(保留两位小数)
所以,供给25头牛吃,这片青草可以吃约19.13天。
相关问题
有一个牧场,牧场上的牧草每天都在匀速生长,这片牧场可供15头牛吃20天,或可供20头牛吃10天,那么,这片牧场每天新生的草量可供几头牛吃1天?用c++写出
根据题目可知,牧场上每天匀速生长的草量为X,那么题目所给的两组数据可以转化为以下两个方程组:
15X * 20 = S (15头牛吃20天)
20X * 10 = S (20头牛吃10天)
其中S为牧场总面积。
解方程组得:X = S/300
因此,每天新生的草量可供n头牛吃1天的草量为:X/n = S/(300n)
以下是对应的C++代码实现:
```c++
#include <iostream>
using namespace std;
int main() {
int s = 0;
for (int i = 1; i <= 300; i++) {
if (15 * i * 20 == 20 * i * 10) {
s = 15 * i * 20;
break;
}
}
int n = 10;
double x = s / 300.0;
double res = x / n;
cout << "每天新生的草量可供" << n << "头牛吃1天的草量为:" << res << endl;
return 0;
}
```
输出结果为:
```
每天新生的草量可供10头牛吃1天的草量为:0.015
```
使用JAVA先说明由几个类;然后确定类和类(接口)的关系,画出类图;再编程来实现模拟一下开心牧场;农场中有农户,各种动物(牛,马,羊,鸡等),农户可以喂养动物;
首先,我们需要创建以下类:
1. Farm:农场类,包含农户和动物。
2. Farmer:农户类,可以喂养动物。
3. Animal:动物类,包括牛、马、羊和鸡。
类图如下:
```
+----------------+ +----------------+ +----------------+
| Farm | | Farmer | | Animal |
+----------------+ +----------------+ +----------------+
| - farmers: List<Farmer> | | - name: String | | - name: String |
| - animals: List<Animal> | +----------------+ | - type: String |
+-----------------------+ | + feed(animal:Animal): void | +----------------+
+--------------------------+
```
接下来,我们来编写代码实现模拟开心牧场:
```
// Animal.java
public abstract class Animal {
private String name;
private String type;
public Animal(String name, String type) {
this.name = name;
this.type = type;
}
public String getName() {
return name;
}
public String getType() {
return type;
}
public abstract void makeSound();
}
// Cow.java
public class Cow extends Animal {
public Cow(String name) {
super(name, "cow");
}
@Override
public void makeSound() {
System.out.println("Moo!");
}
}
// Horse.java
public class Horse extends Animal {
public Horse(String name) {
super(name, "horse");
}
@Override
public void makeSound() {
System.out.println("Neigh!");
}
}
// Sheep.java
public class Sheep extends Animal {
public Sheep(String name) {
super(name, "sheep");
}
@Override
public void makeSound() {
System.out.println("Baa!");
}
}
// Chicken.java
public class Chicken extends Animal {
public Chicken(String name) {
super(name, "chicken");
}
@Override
public void makeSound() {
System.out.println("Cluck!");
}
}
// Farmer.java
public class Farmer {
private String name;
public Farmer(String name) {
this.name = name;
}
public void feed(Animal animal) {
System.out.println(name + " is feeding " + animal.getName() + " the " + animal.getType());
}
}
// Farm.java
import java.util.ArrayList;
import java.util.List;
public class Farm {
private List<Farmer> farmers;
private List<Animal> animals;
public Farm() {
farmers = new ArrayList<>();
animals = new ArrayList<>();
}
public void addFarmer(Farmer farmer) {
farmers.add(farmer);
}
public void addAnimal(Animal animal) {
animals.add(animal);
}
public void feedAnimals() {
for (Farmer farmer : farmers) {
for (Animal animal : animals) {
farmer.feed(animal);
}
}
}
}
// Main.java
public class Main {
public static void main(String[] args) {
Farm farm = new Farm();
Farmer farmer1 = new Farmer("John");
Farmer farmer2 = new Farmer("Jane");
farm.addFarmer(farmer1);
farm.addFarmer(farmer2);
Animal cow1 = new Cow("Bessie");
Animal cow2 = new Cow("Maggie");
Animal horse1 = new Horse("Black Beauty");
Animal sheep1 = new Sheep("Dolly");
Animal sheep2 = new Sheep("Molly");
Animal chicken1 = new Chicken("Chickie");
farm.addAnimal(cow1);
farm.addAnimal(cow2);
farm.addAnimal(horse1);
farm.addAnimal(sheep1);
farm.addAnimal(sheep2);
farm.addAnimal(chicken1);
farm.feedAnimals();
}
}
```
以上代码模拟了开心牧场,包括农户和动物。运行程序将输出以下内容:
```
John is feeding Bessie the cow
John is feeding Maggie the cow
John is feeding Black Beauty the horse
John is feeding Dolly the sheep
John is feeding Molly the sheep
John is feeding Chickie the chicken
Jane is feeding Bessie the cow
Jane is feeding Maggie the cow
Jane is feeding Black Beauty the horse
Jane is feeding Dolly the sheep
Jane is feeding Molly the sheep
Jane is feeding Chickie the chicken
```
相关推荐
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)