时间限制: 1 Sec 内存限制: 128 MB
提交: 172 解决: 60
[提交] [状态] [讨论版] [命题人:外部导入]
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;
}
1014: 奇怪的餐厅(2015年中南大学研究生复试机试题 )
原文:https://www.cnblogs.com/tangyimin/p/10547792.html