HDU 3349 lazy gege【数学几何】

2 篇文章 0 订阅

题目来戳呀

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,那么长方形的方法一定是把长方形向正方形的角上放,这样可以保证长方形的重心在占用面积尽可能小的前提下放入正方形。
分三种情况讨论:
1.长方形的中心不到正方形的中心
2.长方形的中心在正方形的中心上
3.长方形的中心过了正方形的中心

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
int main()
{
    int T;
    double s=0;
    double l,a,b;
    scanf("%d",&T);
    while(T--)
    {
        cin>>l>>a>>b;
        if(a>b) swap(a,b);//我们后来比较的都是短边==
        double k=sqrt(2.0)*l;
        if(a>k&&a<2*k)
            s=l*l-(k-a/2.0)*(k-a/2.0);//正方形的面积减去小等腰直角三角形的面积就是剩下的
        else if(a>2k)
            s=l*l;
        else//矩形中心在正方形以下即本子的中心在桌子的一个角上
            s=a*a/4.0;
        printf("%.4lf\n",s);
    }
    return 0;
}

ps:我简直是要死在数学几何上了orz我哪能想到重心与中心的比较啊摔!分类讨论都想了好久,果然还是辣鸡QAQ

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值