一道C或者C++编程题
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了一道C或者C++编程题相关的知识,希望对你有一定的参考价值。
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
• Newspapers not sold by the end of the day are sold as scrap for 2 cents each
a. Simulate the system for 20 days. Determine the optimal number of newspapers to be purchased daily.
b. The book presents the formula for profit in the form:
Profit = revenue from sales – cost of newspapers – lost profit from excess demand+ salvage from sale of scrap paper
不过算下来好像应该是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;
参考技术A 代码写错了!不成功的! 参考技术B 看来我得去学英语了 参考技术C 不好意思帮不上你了 参考技术D 看不懂
以上是关于一道C或者C++编程题的主要内容,如果未能解决你的问题,请参考以下文章