一道C或者C++编程题

来源:百度知道 编辑:UC知道 时间:2024/06/24 16:42:39
The single-period inventory model: the newspaper seller’s problem. The newspaper boy must decide in the morning how many newspapers he should purchase to be sold during the day.

• He can buy newspapers for 13 cents each and sell them for 20 cents.
• He can purchase newspapers only in bundles of 10.
• The probability distribution for the demand is given in the following table.
Probability of newsday

Types of newsdays probability
good 0.35
fair 0.45
poor 0.2

Distribution of demands Probability
good newsday fair newsday poor newsday
40 0.03 0.1 0.44
50 0.05 0.18 0.22
60 0.15 0.4 0.16
70 0.2 0.2 0.12
80 0.35 0.08 0.06
90 0.15 0.04 0
100 0.07 0 0

题意理解不是很清楚
不过算下来好像应该是60利润最高
Profit = revenue from sales – cost of newspapers – lost profit from excess demand+ salvage from sale of scrap paper
这里的利润计算公式有些奇怪~~~

#include<iostream>
using namespace std;

#define N 7
double DDP[N][4]={
{40,0.03,0.1,0.44},
{50,0.05,0.18,0.22},
{60,0.15,0.4,0.16},
{70,0.2,0.2,0.12},
{80,0.35,0.08,0.06},
{90,0.15,0.04,0},
{100,0.07,0,0}};

int main()
{
double Profit;
int days=20,i,d;
for(i=0;i<N;i++)
{
Profit=0.0;
for(d=0;d<days;d++)
{
double p=DDP[i][1]+DDP[i][2]+DDP[i][3];
Profit+=DDP[i][0]*p*20.0;
Profit-=DDP[i][0]*13.0;
Profit+=DDP[i][0]*(1-p)*2.0;
}
printf("%d Profit=%.2f\n",(int)DDP[i][0],Profit);
}
return 0;
}

代码写错了!不成功的!

看来我得去学英语了

不好意思帮不上你了

看不懂