标签:ext capacity 空格 ring 输入 for new 汽车 normal
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#define FOR(i,x,n) for(long i=x;i<n;i++)
#define ll long long int
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define MAX_N 50005
using namespace std;
struct node{int g,p;double unitPrice;};
node d[10005];
int cmp(node a,node b){
return a.unitPrice>b.unitPrice;
}
int main()
{
//freopen("input1.txt", "r", stdin);
//freopen("data.out", "w", stdout);
int N,W;
scanf("%d %d",&N,&W);
if(N==0&&W==0){
printf("0");
}
int capacity=W;
double value=0;
FOR(i,0,N){
scanf("%d %d",&d[i].g,&d[i].p);
d[i].unitPrice=d[i].p*1.0/d[i].g;
}
sort(d,d+N,cmp);
FOR(i,0,N){
if(capacity-d[i].g>0||capacity-d[i].g==0&&capacity==0){
capacity-=d[i].g;
value+=d[i].p;
}else if(capacity-d[i].g==0&&capacity!=0){
capacity-=d[i].g;
value+=d[i].p;
printf("%.1lf",value);
return 0;
}else if(capacity-d[i].g<0){
value+=d[i].unitPrice*capacity;
capacity=0;
printf("%.1lf",value);
return 0;
}
}
printf("%.1lf",value);
//fclose(stdin);
//fclose(stdout);
return 0;
}
/*
3 0
0 1
0 2
1 1
*/
标签:ext capacity 空格 ring 输入 for new 汽车 normal
原文地址:http://www.cnblogs.com/TWS-YIFEI/p/6544666.html