问题:有A、B两架飞机,A需要2名驾驶员,可载
问题:有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);
}