#include<bits> using namespace std; const int N = 10; int n; int p[10], w[10]; bool st[10]; bool f = 0; double ans = -1; void dfs(int x) { if(x >= 3) { for(int i = 1; i <= x - 2; i++) { for(int j = 1; j <= x - 2; j++) { if(i + j > x - 1) continue; int a = 0, b = 0, c = 0; for(int q = 1; q <= i; q++) a += w[q]; for(int q = i + 1; q <= i + j; q++) b += w[q]; for(int q = i + j + 1; q <= x; q++) c += w[q]; if(a + b > c && b + c > a && a + c > b) { f = 1; double ppp = (a + b + c) / 2.0; double ttt = sqrt(ppp * (ppp - a) * (ppp - b) * (ppp - c)); ans = max(ans, ttt); } } } if(x == n) return; } for(int i = 1; i <= n; i++) { if(st[i] == 0) { st[i] = 1; p[x] = i; dfs(x + 1); st[i] = 0; } } } void solve() { scanf("%d", &n); for(int i = 1; i <= n; i++) scanf("%d", &w[i]); dfs(0); if(f) printf("%.1f\n", ans); else puts("-1"); } int main() { int T = 1; // cin >> T; while(T -- ) { solve(); } return 0; } 老哥,我这个C题只能过个七十几 不知道哪里错了。。</bits>
点赞

相关推荐

01-07 15:50
四川大学 Java
看日出看日落:好好背八股,做算法。我身边跟你bg差不多的基本都大厂暑期
点赞 评论 收藏
分享

牛客热帖

更多
牛客网
牛客企业服务