HDU 3349 lazy gege(水题)

本文介绍了一道经典的算法题,即如何计算将一个矩形笔记本放置于正方形桌面上所需的最小清理面积。通过数学分析得出,当笔记本的一个角与桌面的对角线对齐时,所需清理的面积最小。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3349

Problem Description
Gege hasn't tidied his desk for long,now his desk is full of things.
This morning Gege bought a notebook,while to find somewhise to put it troubles him.
He wants to tidy a small area of the desk, leaving an empty area, and put the notebook there, the notebook shouldn't fall off the desk when putting there.
The desk is a square and the notebook is a rectangle, area of the desk may be smaller than the notebook.
here're two possible conditions:

Can you tell Gege the smallest area he must tidy to put his notebook?
 

Input
T(T<=100) in the first line is the case number.
The next T lines each has 3 real numbers, L,A,B(0< L,A,B <= 1000).
L is the side length of the square desk.
A,B is length and width of the rectangle notebook.
 

Output
For each case, output a real number with 4 decimal(printf("%.4lf",ans) is OK), indicating the smallest area Gege should tidy.
 

Sample Input

 
3
10.1 20 10
3.0 20 10
30.5 20.4 19.6
 

Sample Output

 
25.0000
9.0000
96.0400
 

题目大意:矩形书本a*b放在正方形桌子上L*L,求最小接触面积

题目思路:由正方形顶点对着书本肯定最小,刚好放到矩形宽的一半即可


代码:

#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<stack>
#include<map>

using namespace std;

#define FOU(i,x,y) for(int i=x;i<=y;i++)
#define FOD(i,x,y) for(int i=x;i>=y;i--)
#define MEM(a,val) memset(a,val,sizeof(a))
#define PI acos(-1.0)

const double EXP = 1e-9;
typedef long long ll;
typedef unsigned long long ull;
const int INF = 0x3f3f3f3f;
const ll MINF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9+7;
const int N = 1e6+5;

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    std::ios::sync_with_stdio(false);
    int t;
    double L,a,b;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%lf%lf%lf",&L,&a,&b);
        if(a>b)
            swap(a,b);
        double len = sqrt(2.0)*L/2;  //对角线一半
        double tmp = a/2;
        double x=2*len-tmp;
        if(tmp>len*2)
            printf("%.4lf\n",L*L);
        else if(tmp<len)
            printf("%.4lf\n",tmp*tmp);
        else
            printf("%.4lf\n",L*L-x*x);
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值