Hex Artifact Content
Not logged in

Artifact 959cda21c7e42a70dc6791077e124c0aebde0573:


0000: 2f 2f 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  //--------------
0010: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0020: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0030: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a  ---------------.
0040: 2f 2f 20 41 72 65 61 20 6f 66 20 61 20 70 6f 6c  // Area of a pol
0050: 79 67 6f 6e 0a 2f 2f 20 20 20 4f 28 4e 29 0a 2f  ygon.//   O(N)./
0060: 2f 0a 2f 2f 20 56 65 72 69 66 69 65 64 20 62 79  /.// Verified by
0070: 0a 2f 2f 20 20 20 2d 20 53 52 4d 20 33 33 37 20  .//   - SRM 337 
0080: 44 69 76 31 20 4c 56 33 0a 2f 2f 20 20 20 2d 20  Div1 LV3.//   - 
0090: 53 52 4d 20 34 38 36 20 44 69 76 31 20 4c 56 33  SRM 486 Div1 LV3
00a0: 0a 2f 2f 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  .//-------------
00b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
00c0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
00d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
00e0: 0a 0a 64 6f 75 62 6c 65 20 6f 75 74 65 72 5f 70  ..double outer_p
00f0: 72 6f 64 28 20 70 74 20 61 2c 20 70 74 20 62 20  rod( pt a, pt b 
0100: 29 0a 7b 0a 09 72 65 74 75 72 6e 20 28 61 2e 72  ).{..return (a.r
0110: 65 61 6c 28 29 2a 62 2e 69 6d 61 67 28 29 20 2d  eal()*b.imag() -
0120: 20 62 2e 72 65 61 6c 28 29 2a 61 2e 69 6d 61 67   b.real()*a.imag
0130: 28 29 29 2f 32 3b 0a 7d 0a 0a 64 6f 75 62 6c 65  ())/2;.}..double
0140: 20 61 72 65 61 28 20 63 6f 6e 73 74 20 76 65 63   area( const vec
0150: 74 6f 72 3c 70 74 3e 26 20 71 20 29 0a 7b 0a 09  tor<pt>& q ).{..
0160: 64 6f 75 62 6c 65 20 61 20 3d 20 30 2e 30 3b 0a  double a = 0.0;.
0170: 0a 09 70 74 20 6f 20 3d 20 71 5b 30 5d 3b 0a 09  ..pt o = q[0];..
0180: 66 6f 72 28 69 6e 74 20 69 3d 31 3b 20 69 2b 31  for(int i=1; i+1
0190: 3c 71 2e 73 69 7a 65 28 29 3b 20 2b 2b 69 29 0a  <q.size(); ++i).
01a0: 09 09 61 20 2b 3d 20 6f 75 74 65 72 5f 70 72 6f  ..a += outer_pro
01b0: 64 28 71 5b 69 5d 2d 6f 2c 20 71 5b 69 2b 31 5d  d(q[i]-o, q[i+1]
01c0: 2d 6f 29 3b 0a 09 72 65 74 75 72 6e 20 61 62 73  -o);..return abs
01d0: 28 61 29 20 2f 20 32 3b 0a 7d 0a                 (a) / 2;.}.