问题:有A、B两架飞机,A需要2名驾驶员,可载

mobydick 2004-02-18 11:01:05
问题:有A、B两架飞机,A需要2名驾驶员,可载30人;B需要1名驾驶员,可载20人。现有A20架,B40架,驾驶员50名。问,分别用多少架A、B才能使所载人员最多。(A、B驾驶员可通用)

能不能不用循环解决这一道题。

class plane()
{
private pilot;
private carry;

public void setPilot(int i)
{
pilot = i;
}

public void setCarry(int i)
{
carry = i;
}

public int getPilot()
{
return pilot;
}

public int getCarry()
{
return carry;
}
}

struct max
{
int p;
int c;
}

public static void Main()
{
int x = 1, y = 1, m = 0, n = 0;

max maxC = new max;
maxC.p = 0;
maxC.c = 0;

plane A = new plane();
plane B = new plane();

A.setPilot = 2;
A.setCarry = 30;
B.setPilot = 1;
B.setCarry = 20;

for(x = 1; x < 20; x++)
for(y = 1; y < 40; y++)
{
n = x*A.getPilot + y*B.getPilot; //number of pilot

if(n <= 50)
{
m = x*A.getCarry + y*B.getCarry; //number of soldier

if(maxC.c < m)
{
maxC.p = n;
maxC.c = m;
}
}
}
Console.WriteLine(maxC.p+"\r\n"+maxC.c);
}
...全文
119 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧