[ZCMU OJ]5198: Mona Lisa‘s smile(思路记录)

5198: Mona Lisa's smile

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 101  Solved: 30
[Submit][Status][Web Board]

Description

When Leonardo da Vinci's famous painting "Mona Lisa's smile" was born, Leonardo da Vinci was ready to hang it on the wall. First, take a closer look. In order to hang the picture, you need to nail a nail in the wall. After the nail is nailed, the connecting line between the nail and the four corners of the wall divides the wall into several disjoint areas with an area greater than zero. Leonardo da Vinci is not only a master of art, but also a mathematical genius. He wanted to know: which of these disjoint areas has the smallest area? Can you help him figure it out? Suppose the wall is a square with side length A, and the distance between the nail and the upper and left margins of the wall are B and C respectively.

Input

The input has multiple cases (no more than 100) of test data.

Each test case occupies one line, which are three integers A(1 ≤ A ≤ 100)、B(0 ≤ B ≤ A)and C(0 ≤ C ≤ A), representing the side length of the square wall and the distance between the nail and the upper and left margins of the wall.

The end of input will be represented by a line of test case where A、B and C are equal to 0. This test case should not be processed.

Output

Each test case outputs a line, which is a real number, that is, the area of the smallest area, which is rounded to one decimal place.

Sample Input

4 1 1

6 2 1

0 0 0

Sample Output

2.0

3.0

_____________________________________________________________________________

这道题的意思是:一个正方形内任意找一个点,连线到四个顶点;连线之后正方形被分成四个区域,求这四个区域中最小的那一块区域。

这四块区域无非都是三角形,所以我的思路(有漏洞的)一开始是:找到四个三角形的高,再找到最小的那个高,就可以求到最小的那块面积。但是这题得考虑到一种边界情况,例如:“4 0 0”。这个时候输出应该是8.0(4*4/2)。但是很不幸的是wa了。

#include<bits/stdc++.h>
using namespace std;
int main()
{
	double bian,shang,zuo;
	while(cin>>bian>>shang>>zuo)
	{
		double heng,shu,min_one;
		heng=min(shang,bian-shang);
		shu=min(zuo,bian-zuo);
		
		if(heng==0||shu==0)
		{
			heng=bian;
			shu=bian;
		}
		
		min_one=min(heng,shu);
		
		double min_area=bian*min_one/2;
		
		if(min_area)
		printf("%.1lf\n",min_area);
	}
}

后来换了一种思路:既然找最小的面积,那就直接把四块面积算出来找到最小的面积就好了,(最小的面积也得大于0)这样也避免了上一种思路得逻辑漏洞。

#include<bits/stdc++.h>
using namespace std;
int main()
{
	double bian,zuo,shang;
	while(cin>>bian>>zuo>>shang)
	{
		double s[4];
		s[0]=bian*zuo/2;
		s[1]=bian*shang/2;
		s[2]=bian*(bian-zuo)/2;
		s[3]=bian*(bian-shang)/2;
		
		sort(s,s+4);
		for(int i=0;i<4;i++)
		{
			if(s[i])
			{
				printf("%.1lf\n",s[i]);
				break;
			}
		}
	}
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值