山大华特卧龙学校第一届ACM赛后总结_题目

题目B

题目背景
水之积也不厚,则其负大舟也无力。——《逍遥游》

题目描述
为了承载起给定的 个长方体木块,水的深度至少为多少。

输入输出格式

输入格式

第一行一个整数 ,表示给定 个木块。
接下来 行,每行四个实数 ,表示木块三边长和密度。数据保证 ,精确到小数点后两位。水的密
度视为1。

输出格式

一个实数,表示要想使得 个木块都浮起来,水的深度最少为多少。精确到小数点后两位。

友情提示:物体在水中所受到的水的浮力为: F = ρ g V F = ρ_水gV_排 F=ρgV

输入输出样例
输入样例

3
0.5 0.5 0.5 0.5
2.0 3.0 1.0 0.5
4.0 4.0 4.0 0.2

输出样例

0.80

思路

这道题说实话也属于签到题

我们可以轻易的推出一个式子: h = ρ ρ c h_深 = \frac{ρ_物}{ρ_水}*c h=ρρc

然而我们只要知道c就好了

很显然,c就是三条边里最短的那一条

上来就AC了

code

#include <iostream>
#include <cstdio>
#include <string.h>
#include <algorithm>
#include <math.h>
using namespace std ;
int n , m ;
double p_w = 1.00 ;
double maxx = -10 ;
int main() {
    scanf("%d",&n) ;
    double a,b,c,p ;
    double ans ,cc;
    for(int i = 1 ; i <= n ; i ++) {
        scanf("%lf%lf%lf%lf",&a,&b,&c,&p) ;
        cc = min (min(a,b),c) ;
        ans = p/p_w * cc ;
        maxx = max(maxx,ans) ;
    }
    printf("%.2lf\n",maxx) ;
    
    return 0;
}

贼短…