P5951的题解

· · 题解

(一)

如果你上过初二科学课的话,你一定会知道:物体排开水的体积 \times 水的密度 = 物体的质量。

(二)

AC 代码。

#include<bits/stdc++.h>
using namespace std;
int s,h,v,n;
double hnow,a,b;
int main(){
    scanf("%d%d%d",&s,&h,&v);
    double hnow=v*1.0/s;
    scanf("%d",&n);
    while(n--){
        scanf("%lf%lf",&a,&b);
        if(b>=1)hnow+=a*a*a/s;
        else hnow+=a*a*a*b/s;
    }
    printf("%.7lf",min(h*1.0,hnow));
    return 0;
}