1014: 奇怪的餐厅(2015年中南大学研究生复试机试题 )

014: 奇怪的餐厅

时间限制: 1 Sec  内存限制: 128 MB
提交: 172  解决: 60
[提交] [状态] [讨论版] [命题人:外部导入]

题目描述

鲁大师和他的朋友经常去一家奇怪的餐厅,为什么说奇怪呢,一是餐厅提供的菜品比较奇怪,二是餐厅的付费规则比较奇怪,每个人有不同的折扣上限(单人从总结里折算的最高金额),超过折扣上限的部分原价付费(N个人可以每人出一部分),这次鲁大师和魏然层风以及朋友一共N个人去这家餐厅吃饭,他们点的菜品总金额为T,现在告诉你每个人的折扣率z和折扣上限H,请告诉他们最少需要支付多少钱?

输入

输入数据有多组,每组占N+1行,第一行是N和T,接下来N行,每行两个数字z和H(0<N<100)。

输出

对于每组输入数据,输出一行,对应一个要求的答案。答案向下取整。

样例输入

2 100
0.7 70
0.6 50
3 500
0.6 100
0.8 200
0.7 100
1 100
0.6 100

样例输出

65
390
60

#include<iostream>
#include<math.h>
using namespace std;

double discount33[100];//对应折扣 
int total33[100];//对应打折上限 
/*总结:要清楚理解题意,并把可能的情况都考虑进去,比如此题的,折扣用完的情况 
*/
int main(){
    int N,T;
    while(cin>>N>>T){
        for(int i=0;i<N;i++){
            cin>>discount33[i]>>total33[i];
        }
        //对折扣顺序进行排序 
        for(int i=0;i<N;i++){
            for(int j=0;j<N-i-1;j++){
                if(discount33[j]>discount33[j+1]){
                    double temp=discount33[j];
                    discount33[j]=discount33[j+1];
                    discount33[j+1]=temp;
                    int temp1=total33[j];
                    total33[j]=total33[j+1];
                    total33[j+1]=temp1;
                }
            }
        }
        //计算价格,从折扣高的 开始计算
        int totalMoney=0;
        int curMoney=T;
        for(int k=0;k<N;k++){
            //cout<<curMoney<<"**"<<total33[k]<<endl;
            if(curMoney>total33[k]){
                totalMoney+=total33[k]*discount33[k];
                curMoney-=total33[k];
                //cout<<"curMoney: "<<curMoney<<" totalMoney: "<<totalMoney<<endl;
            }
            else{//已经结算清楚了 
                totalMoney+=curMoney*discount33[k];
                curMoney=0;
                //cout<<"curMoney: "<<curMoney<<" totalMoney: "<<totalMoney<<endl;
                break;
            }
        }
        //有可能折扣用完了,还没结算清楚
        if(curMoney!=0){
            totalMoney+=curMoney;
        } 
        cout<<totalMoney<<endl;
         
    }
    return 0;
}
 

猜你喜欢

转载自www.cnblogs.com/tangyimin/p/10547792.html
今日推荐