CodeForces

题目链接

题目大意

  在n块(W imes H)的地里建两个建筑,可以建在同一块地,也可分开,建筑与边界平行。

解题思路

  建在同一块地很好算,主要是建在不同的地里怎么算。首先将长边从大到小排序,然后开始遍历,将当前的长边当作建筑的一边,而将之前的最长的短边与现在的短边取最小值,显然之前遍历过的地里就有包括当前的情况的地。
  还有一点需要注意的就是,题目给的数字很大,double的有效数字不够表示那么多位,就会出现精度误差,所以最好用long long。

代码

const int maxn = 2e5+10;
const int maxm = 3e6+10;
struct INFO {
	ll x, y;
} info[maxn];
int n;
int main(){
	cin >> n;
	for (int i = 1; i<=n; ++i) {
		cin >> info[i].x >> info[i].y;
		if (info[i].x > info[i].y) swap(info[i].x, info[i].y);
	}
	sort(info+1, info+n+1, [](INFO a, INFO b) {return a.y>b.y;});
	ll ans = info[1].x*info[1].y, maxx = info[1].x, maxy = info[1].y;
	for (int i = 2; i<=n; ++i) {
		ans = max(ans, info[i].x*info[i].y);
		ans = max(ans, min(maxx, info[i].x)*info[i].y*2);
		maxx = max(maxx, info[i].x);
	}
	if (ans&1) printf("%lld.5
", (ans-1)/2);
	else printf("%lld.0
", ans/2);
	return 0;	
}
原文地址:https://www.cnblogs.com/shuitiangong/p/14399509.html