Sicily 1093 Air Express
来源:互联网 发布:苏州淘宝运营 编辑:程序博客网 时间:2024/05/22 06:27
/*按照题意操作即可,把重量一直增加到 w3+1 为止 *//*Run Time: 0secsRun Memory: 312KB*/#include <iostream>#include <vector>using namespace std;int rate[5]; //{0, r1, r2, r3, r4}int weight[4]; //{0, w1, w2, w3}vector<int> packages;inline int computeCost(int w){ if(w <= weight[1]) return w * rate[1]; else if(w <= weight[2]) return w * rate[2]; else if(w <= weight[3]) return w * rate[3]; else return w * rate[4];}void compute(){ for(int i=0; i<packages.size(); i++){ int bufW = packages[i]; int cost = computeCost(bufW); int newCost = cost; int newW = bufW; while(bufW++ < weight[3]+1){ cost = computeCost(bufW); if(cost < newCost){ newCost = cost; newW = bufW; } } cout << "Weight (" << packages[i] << ") has best price $" << newCost << " (add " << newW-packages[i] << " pounds)" << endl; }}int main(){ int num = 0; int buf; while (cin>>buf && buf){ num++; weight[0] = rate[0] = 0; weight[1] = buf; cin >> rate[1] >> weight[2] >> rate[2] >> weight[3] >> rate[3] >> rate[4]; if(packages.size() != 0) packages.clear(); while(1){ cin >> buf; if(buf == 0) break; packages.push_back(buf); } cout << "Set number " << num << ":" << endl; compute(); cout << endl; } return 0;}