1070 Mooncake (25)

#include
using namespace std;
const int MAXN=1001;
struct Node{
	double num;
	double price;
	Node(){
		num=0;
		price=0;
	} 
}node[MAXN];
bool cmp(Node a,Node b){
	if(a.price!=b.price) return a.price>b.price;
}
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
	#endif
	int n,d;
	cin>>n>>d;
	for(int i=0;i>node[i].num;
	}
	for(int i=0;i>temp;
		node[i].price=temp/node[i].num;
	}
	sort(node,node+n,cmp);
	double ans=0;
	for(int i=0;inode[i].num){
			ans=ans+node[i].price*node[i].num;
			d=d-node[i].num;
		}else{
			ans=ans+node[i].price*d;
			d=0;
		}
	}
	printf("%.2lf",ans);
	return 0;
}

 

你可能感兴趣的:(C++/PAT/洛谷OJ)