P5951题解
Part 1
初中生都熟悉这题,这是浮力中的基本运算;
但是这里有一个坑点,就是密度比水小的物体会浮在水面上,导致物体不能完全浸入,所以我们在算的时候应该判定是否全部浸入。
本题运算基本公式: 浸入体积等于重力除以密度乘重力的比例系数。
Part 2
Code
#include<iostream>
#include<cstdio>
#include<cmath>
#include<ctime>
#include<algorithm>//sort函数库
#include<cstdlib>
#include<cstring>
#include<bits/stdc++.h>
#include<map>
#define gets(S) fgets(S,sizeof(S),stdin)
#pragma optimize GCC(2)
using namespace std;
int s,h,v,n;
double len,rou;
int main()
{
cin>>s>>h>>v>>n;
double hf=1.0*v/s;//1.0是为了转换为浮点数
for(int i=1;i<=n;i++)
{
scanf("%lf%lf",&len,&rou);
if(rou>=1)//判断是否浸入
{
hf+=(len*len*len)/s;
}
else
{
hf+=(len*len*len*rou)/s;
}
if(hf>=h)//如果超出范围则直接输出
{
printf("%d",h);
return 0;
}
}
printf("%.7f",hf);
return 0;
}