E题10分求条

#include <bits/stdc++.h>
using namespace std;

double helen(double a, double b, double c) {
	double p = (a + b + c) / 2;
	double res = sqrt(p * (p - a) * (p - b) * (p - c));
	return res;
}
int T;
int n;
typedef pair<int, int> PII;
typedef long long ll;
int ma1, ma2, ma3;

void getma(int x) {
	if (x > ma1) {
		ma3 = ma2;
		ma2 = ma1;
		ma1 = x;
	} else if (x > ma2) {
		ma3 = ma2;
		ma2 = x;
	} else if (x > ma3) {
		ma3 = x;
	}
}
map<int, ll, greater<int> > tbl;
int main() {
	scanf("%d",&T);
	while (T--) {
		scanf("%d", &n);
		tbl.clear();
		ma1 = 0, ma2 = 0, ma3 = 0;
		ll lsum = 0;
		for (int i = 1; i <= n; i++) {
			int a;
			ll b;
			scanf("%d%lld", &a, &b);
			lsum += b;
			if (tbl.find(a) != tbl.end()) {
				tbl[a] += b;
			} else {
				tbl[a] = b;
			}
			for (int j = 1; j <= min(b, 3ll); j++) {
				getma(a);
			}
		}
		if (lsum < 3 || ma2 + ma3 <= ma1 /*|| (ma1!=ma2 &&ma1!=ma3)*/) {
			puts("-1");
			continue;
		}
		bool flag = false;
		for (map<int, ll, greater<int> >::iterator it = tbl.begin(); it != tbl.end(); it++) {
//			printf("debug : %d\n", it->first);
			if (it->second >= 3) {
				printf("%.9lf\n", helen(it->first, it->first, it->first));
				flag = true;
				break;
			}
			
			if (next(it) == tbl.end())
				break;
			ll t1 = it->second;
			double s1 = it->first;
			ll t2 = next(it)->second;
			double s2 = next(it)->first;
			
			if (t1 + t2 >= 3 && t1 == 1 && s2 + s2 > s1) {
				printf("%.9lf\n", helen(s1, s2, s2));
				flag = true;
				break;
			}
			if (t1 + t2 >= 3 && t1 == 2) {
				printf("%.9lf\n", helen(s1, s1, s2));
				flag = true;
				break;
			}
		}
		if (!flag) {
			puts("-1");
		}

	}
	return 0;
}

全部评论
我也是10分,对拍也拍不出来,不知道为什么
点赞 回复 分享
发布于 2024-12-09 23:41 河北

相关推荐

码农索隆:有点耳熟,你们是我教过最差的一届
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务