3-50 2.2.1

#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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值