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