0%
链接
传送门
题意
给出计算公式,求最小值。
思路
枚举全盘列。
代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> using namespace std;
const int inf = 0x3f3f3f3f; const int maxn = 10; int a[maxn];
double cal() { return sqrt((a[0] + a[1] + a[2] - a[5] - a[6] - a[7]) * (a[0] + a[1] + a[2] - a[5] - a[6] - a[7]) + (a[0] + a[3] + a[5] - a[2] - a[4] - a[7]) * (a[0] + a[3] + a[5] - a[2] - a[4] - a[7])); }
int main() { while (~scanf("%d", &a[0])) { int cnt = a[0] == 0 ? 1 : 0; for (int i = 1; i < 8; ++i) { scanf("%d", &a[i]); if (a[i] == 0) { ++cnt; } } if (cnt == 8) { break; } double ans = inf; sort(a, a + 8); do { ans = min(ans, cal()); } while (next_permutation(a, a + 8)); printf("%.3f\n", ans); } return 0; }
|