4 条题解

  • 0
    @ 2024-4-8 14:57:09
    #include<iostream>
    #include<string>
    #include<cmath>
    #include<algorithm>
    #include<cstdio>
    using namespace std;
    const int N=102;
    int n,zhilian;
    struct gold{
    	double weight;
    	double worth;
    	double every;
    }go[N];
    bool compair(gold a,gold b){
    	return a.every>b.every;
    }
    int main(){
    	cin>>n>>zhilian;
    	int i=0;
    	int t=n;
    	while(t--){
    		int x1,x2;
    		scanf("%d%d",&x1,&x2);
    		go[i].weight=x1,go[i].worth=x2;
    		go[i].every=(double)x2/x1;
    		i++;	
    	}
    	sort(go,go+n,compair);
    	double res=0;
    	for(int j=0;j<n;j++){
    		if(zhilian>go[j].weight) res+=go[j].worth,zhilian-=go[j].weight;
    		else {
    			res+=go[j].every*zhilian;
    			break;
    		}
    	}
    	printf("%.2lf",res);
    	return 0;
    	
    }
    

    信息

    ID
    77
    时间
    1000ms
    内存
    256MiB
    难度
    7
    标签
    递交数
    342
    已通过
    82
    上传者