问题 I: Rectangle Cutting----------------------模拟

题目描述
There is a rectangle in a coordinate plane. The coordinates of the four vertices are (0,0), (W,0),
(W,H), and (0,H). You are given a point (x,y) which is within the rectangle or on its border. We will draw a straight line passing through (x,y) to cut the rectangle into two parts. Find the maximum possible area of the part whose area is not larger than that of the other. Additionally, determine if there are multiple ways to cut the rectangle and achieve that maximum.

Constraints
·1≤W,H≤109
·0≤x≤W0≤y≤H
·All values in input are integers.
输入
Input is given from Standard Input in the following format:

W H x y

输出
Print the maximum possible area of the part whose area is not larger than that of the other, followed by 1 if there are multiple ways to cut the rectangle and achieve that maximum, and 0 otherwise.

The area printed will be judged correct when its absolute or relative error is at most 10−9.
样例输入 Copy
【样例1】
2 3 1 2
【样例2】
2 2 1 1
样例输出 Copy
【样例1】
3.000000 0
【样例2】
2.000000 1
提示
The line x=1 gives the optimal cut, and no other line does.

题意:
给你四个点构成矩形,现在有一点在矩形里面,怎么切使得查找面积不大于另一部分的最大可能面积。此外,确定是否有多种方法可以切割矩形并达到该最大值。

解析:
如果给出点位于矩形中间,那么肯定有很多种切法,因为不管怎么切一边的面及<=另一边 且还是最大的。

如果位于其他地方,最大面及就是w*h/2,且不会出现多次这种最大值。


#include<bits/stdc++.h>
using namespace std;
double w,h,x,y;
int main()
{
	cin>>w>>h>>x>>y;
	if(x==w/2&&y==h/2) printf("%.9lf 1\n",w*h/2);
	else printf("%.9lf 0\n",w*h/2);
}
发布了383 篇原创文章 · 获赞 7 · 访问量 8059

猜你喜欢

转载自blog.csdn.net/qq_43690454/article/details/104159721