【ZOJ3919 2016年浙大2月月赛E】【简单计算几何 贪心】Ellipse 椭圆内切圆外切平行四边形最大最小面积

Ellipse Time Limit: 2 Seconds        Memory Limit: 65536 KB        Special Judge

There is an beautiful ellipse whose curve equation is:

\frac {x^2}{a^2} + \frac {y^2}{b^2} = 1 (a > b > 0)
.

There is a parallelogram named P inscribed in this ellipse. At the same time, the parallelogram P is externally tangent to some circle center at the origin (0,0).

Now your task is to output the maximum and minimum area of P among all possible conditions.

Input

The input consists of multiple test cases.

For each test case, there is exactly one line consists of two integers a and b. 0 < b <= a <= 109

Output

For each test case, output one line of two one-space splited numbers: the maximum area and the minimum area. The absolute or relative error of the coordinates should be no more than 10-6.

Sample Input

1 1

Sample Output

2 2
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<ctype.h>
#include<math.h>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<bitset>
#include<algorithm>
#include<time.h>
using namespace std;
void fre() { freopen("c://test//input.in", "r", stdin); freopen("c://test//output.out", "w", stdout); }
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x,y) memcpy(x,y,sizeof(x))
#define MP(x,y) make_pair(x,y)
#define ls o<<1
#define rs o<<1|1
typedef long long LL;
typedef unsigned long long UL;
typedef unsigned int UI;
template <class T1, class T2>inline void gmax(T1 &a, T2 b) { if (b>a)a = b; }
template <class T1, class T2>inline void gmin(T1 &a, T2 b) { if (b<a)a = b; }
const int N = 0, M = 0, Z = 1e9 + 7, ms63 = 0x3f3f3f3f;
double a, b;
int main()
{
	while(~scanf("%lf%lf", &a, &b))
	{
		double maxv = a*b * 2;
		double minv = 4 * a*a*b*b / (a*a + b*b);
		printf("%.15f %.15f\n", maxv, minv);
	}
	return 0;
}
/*
【trick&&吐槽】
不要把最小最大面积搞反了>_<囧

【题意】
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3919
给你一个椭圆。该椭圆的中心为(0,0),方程为
x^2/a^2 + y^2/b^2 =1(1e9>=a>=b>0)
一个平行四边形内切在椭圆内(parallelogram inscribed in this ellipse),
同时,这个平行四边形还要外切于一个圆心为(0,0)的圆(parallelogram P is externally tangent to some circle )
问你,这个平行四边形的最大面积和最小面积分别是多少

【类型】
计算几何 贪心 猜想

【分析】
我们发现,这个平行四边形如果内切一个圆,
就必然是关于圆心中心对称且关于双坐标轴都对称的。
于是这个平行四边形就必然是菱形或正方形。
显然菱形面积最小,正方形面积最大。

如果其为菱形,那面积为a*b/2
如果其为正方形,那其一个顶点必然可以表示为(t,t)。
必然满足t^2/a^2 + t^2/b^2 == 1
即(a^2 + b^2) * t^2 == a^2 b^2
我们求出t^2= (a^2 b^2) / (a^2 + b^2)
面积=4*t^2=4 * (a^2 b^2) / (a^2 + b^2)

【时间复杂度&&优化】
O(1)

*/


你可能感兴趣的:(贪心,计算几何,题库-ZOJ)