#include <iostream>
using namespace std;
typedef struct person{
double discount = 1;
double plimit = 0;
person *next;
}person,*pl;
int cmp(double a,double b){
if(a>=b){
return 1;
}
return 0;
}
void init(pl &p,int N){
p = new person;
p->next = NULL;
pl head = p;
while(N>0){
pl op=new person;
op->next =NULL;
cin>>op->discount>>op->plimit;
pl pre=head;
pl curr = pre->next;
while(pre!=NULL&&curr!=NULL){ //sort
if(op->discount > curr->discount){
pre = curr;
curr = curr->next;
}else{
break;
}
}
pre->next = op;
op->next = curr;//当curr为空时,让next指向他是指向空吗 是的
N--;
}
return;
}
int main(){
int N;
double T;
while(cin>>N>>T){
pl p;
double pay=0;
init(p,N);//初始化person链表;
p = p->next;
while(T>0){
if(!p){
break;
}
if(p->plimit >= T){
pay += T*p->discount;
T = 0;
}else{
pay +=p->discount*p->plimit;
T -= p->plimit;
}
p = p->next;
}
if(T>0) pay += T;
cout<<pay<<endl;
}
return 0;
}
3-50 2.2.1
最新推荐文章于 2024-09-01 22:24:53 发布