首页 > ACM题库 > HDU-杭电 > HDU 3349-lazy gege[解题报告]HOJ
2014
03-16

HDU 3349-lazy gege[解题报告]HOJ

lazy gege

问题描述 :

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:
coins

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

输入:

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.

输出:

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.

样例输入:

3
10.1 20 10
3.0 20 10
30.5 20.4 19.6

样例输出:

25.0000
9.0000
96.0400

点击打开链接

/*

只要让本子的中心在桌子的对角线上就可以了,注意分情况讨论

2013-04-22

*/

#include"stdio.h"
#include"math.h"
int main()
{
    int t;
    double l,a,b,tem;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%lf%lf%lf",&l,&a,&b);
        if(a>b)
        {
            tem=a;
            a=b;
            b=tem;
        }
        if(sqrt(l*l+l*l)<a/2)
            printf("%.4f\n",l*l);
        else if(a/2<sqrt(l*l+l*l)/2)
        {
            printf("%.4f\n",a*a/4);
        }
        else 
        {
            printf("%.4f\n",l*l-(sqrt(l*l*2)-a/2)*(sqrt(l*l*2)-a/2));
        }
    }
    return 0;
}

参考:http://blog.csdn.net/yangyafeiac/article/details/8834134


  1. 我还有个问题想请教一下,就是感觉对于新手来说,递归理解起来有些困难,不知有没有什么好的方法或者什么好的建议?

  2. 第二个方法挺不错。NewHead代表新的头节点,通过递归找到最后一个节点之后,就把这个节点赋给NewHead,然后一直返回返回,中途这个值是没有变化的,一边返回一边把相应的指针方向颠倒,最后结束时返回新的头节点到主函数。