[sicily online]1093. Air Express

來源:互聯網
上載者:User
/*ConstraintsTime Limit: 1 secs, Memory Limit: 32 MBDescriptionFly It Today! (FIT), an air express company, charges different amounts for packages depending on their weight. For example, one set of rates may be:Package weight    Cost per pound0 to 9 pounds             $1010 to 49 pounds         $550 to 99 pounds         $3100 pounds or more  $2This rate structure has upset some customers who have realized that it costs less to ship a 10pound package ($50) than an 8 pound package ($80) and it costs less to ship a 100 poundpackage ($200) than a 90 pound one ($270). FIT wants to check packages to determine if the customer can pay a lower price by adding weight to the package. If this is the case, they want to know the minimum weight to be added to obtain the lowest price possible.InputThe input file will have one or more data sets. Each data set begins with exactly 4 lines, giving the shipping rates. These will be:weight1 rate1weight2 rate2weight3 rate3rate4You may assume all of these values are positive integers less than 1001 and weight1 < weight2 < weight3 . The values represent the rate table below:There will then be 1 or more lines of customer package sizes. Each of these will be a positive integer less than 1001. The end of customer package sizes is indicated by the single integer 0.The end of input will be indicated by end of file.OutputFor each input set, print the input set number. Then, for each of the customer package sizes in the input set, create a line of output formatted as follows:Weight (<w>) has best price $<price> (add <p> pounds)Where <w> is the weight of the customer package, as defined in the input set, <price> is the lowest price the customer can pay to send that package (with, optionally, added weight) based on the input set shipping rates, and <p> is the number of pounds to be added to the package to obtain the price (<p> must be greater than or equal to 0). If more than one different weight results in the best possible price, use the smaller weight.Have a blank line after the output for each input set.Sample Input9 1049 599 3281090100200010 1020 2030 3010011229500Sample OutputSet number 1:Weight (8) has best price $50 (add 2 pounds)Weight (10) has best price $50 (add 0 pounds)Weight (90) has best price $200 (add 10 pounds)Weight (100) has best price $200 (add 0 pounds)Weight (200) has best price $400 (add 0 pounds)Set number 2:Weight (1) has best price $10 (add 0 pounds)Weight (12) has best price $240 (add 0 pounds)Weight (29) has best price $870 (add 0 pounds)Weight (50) has best price $5000 (add 0 pounds)*/#include<iostream>#include<stdio.h>#include<cmath>#include<iomanip>#include <map>#include <vector>#include <string>#include <algorithm>#include <sstream>#include <stack>using namespace std;typedef struct STRPRICE{int high;int price; int cheapPrice;}node;int main(){int a,b;int count=0;while(cin>>a){cin>>b;count++;vector<node> data(4);vector<int> packet;data[0].high=a;data[0].price=b;data[0].cheapPrice=0;for(int i=1;i<3;i++){cin>>data[i].high>>data[i].price;data[i].cheapPrice=(data[i-1].high+1)*data[i].price;}cin>>data[3].price;data[3].cheapPrice=(data[2].high+1)*data[3].price;int x;while(cin>>x&&x!=0)packet.push_back(x);cout<<"Set number "<<count<<":"<<endl;for(vector<int>::size_type i=0;i<packet.size();i++){int j=0;for(j=0;j<3;j++){if(packet[i]<=data[j].high)break;}//end for jint factPrice=data[j].price*packet[i];int minIndex=j;for(int k=j+1;k<4;k++){if(factPrice>data[k].cheapPrice){minIndex=k;factPrice=data[k].cheapPrice;}//end if}//end for kif(minIndex==j)cout<<"Weight ("<<packet[i]<<") has best price $"<<factPrice<<" (add 0 pounds)"<<endl;else cout<<"Weight ("<<packet[i]<<") has best price $"<<factPrice<<" (add "<<data[minIndex-1].high+1-packet[i]<<" pounds)"<<endl;}//end forcout<<endl;}}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.