P1284 triangle farm, p1284 triangle farm
Description
Like everyone else, cows like change. They are imagining new pastures. The dairy architect Hei wants to build a triangle farm surrounded by beautiful white fences. She owns N (3 ≤ N ≤ 40) boards. The length of each Board, Li (1 ≤ Li ≤ 40), is an integer, she wants to build a triangle around all the boards to maximize the farm area.
Please help Miss Hei construct this farm and calculate the maximum farm area.
Input/output format:
Row 1st: an integer N
2nd .. N + 1 rows: each row contains an integer, that is, the length of the Board.
Output Format:
Only one INTEGER: the result of multiplying the maximum farm area by 100 and then giving up. If it cannot be built, output-1.
Input and Output sample input sample #1:
511334
Output sample #1:
692
Description
Example: 692 = after the end (100 x Triangle Area), this triangle is an equilateral triangle with a side length of 4.
We use the three sides of a triangle as the search variable.
When we know the length of two sides, we can introduce the length of the third side.
We have three strategies for every stick.
1. Add to the first edge
2. Add the second edge
3. Add it to the third side.
Then the brute force Memory search will be fine!
1 # include <iostream> 2 # include <cstdio> 3 # include <cstring> 4 # include <cmath> 5 # include <queue> 6 # include <algorithm> 7 # include <map> 8 # define lli long int 9 using namespace std; 10 const int MAXN = 10000001; 11 void read (int & n) 12 {13 char c = '+'; int x = 0; bool flag = 0; 14 while (c <'0' | c> '9') 15 {c = getchar (); if (c = '-') flag = 1 ;} 16 while (c> = '0' & c <= '9') 17 {x = x * 10 + (c-48); c = getchar ();} 18 flag = 1? N =-x: n = x; 19} 20 int n; 21 int fi, se; 22 int vis [MAXN]; 23 int sum = 0; 24 int a [MAXN]; 25 int happen [MAXN]; 26 double ans =-1; 27 map <string, bool> mp; 28 double calc (double yi, double er, double san) 29 {30 if (min (yi, er), min (er, san) + min (yi, er), min (er, san)> max (yi, er), max (er, san) 31 {32 double p = (yi + er + san)/2; 33 return sqrt (p * (p-yi) * (p-er) * (p-san); 34} 35 else36 return-1; 37} 38 int comp (const int, Const int B) 39 {40 return a <B; 41} 42 void dfs (int yi, int er, int san) 43 {44 if (happen [yi * 1500 + er * 150 + san]) 45 return; 46 happen [yi * 1500 + er * 150 + san] = 1; 47 if (yi + er + san = sum & yi! = 0 & er! = 0 & san! = 0) 48 {49 double hh = calc (yi, er, san); 50 if (hh> ans) 51 ans = calc (yi, er, san ); 52} 53 54 for (int I = 1; I <= n; I ++) 55 {56 if (vis [I] = 0) 57 {58 vis [I] = 1; 59 dfs (yi + a [I], er, sum-(yi + a [I] + er )); 60 dfs (yi, er + a [I], sum-(yi + er + a [I]); 61 vis [I] = 0; 62 dfs (yi, er, sum-(yi + er); 63} 64} 65} 66 int main () 67 {68 69 read (n); 70 for (int I = 1; I <= n; I ++) 71 {72 read (a [I]); sum + = a [I]; 73} 74 sort (a + 1, a + n + 1, comp); // The sorting is to facilitate debugging of 75 dfs (0, 0); 76 if (ans =-1) 77 {printf ("-1"); return 0;} 78 ans = ans * 100.0; 79 printf ("% d", (int) ans); 80 return 0; 81}