fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define int long long
  5. struct p{
  6. int x, y;
  7. };
  8. struct vec{
  9. int x, y;
  10. vec(const p& a, const p& b){
  11. x = b.x - a.x;
  12. y = b.y - a.y;
  13. }
  14.  
  15. };
  16.  
  17. ll dot(vec a, vec b){
  18. return a.x * b.x + a.y * b.y;
  19. }
  20.  
  21. ll cross(vec a, vec b){
  22. return 1LL * a.x * b.y - 1LL * b.x * a.y;
  23. }
  24.  
  25. const double eps = 1e-9;
  26.  
  27. int sign(int x){
  28. if(x > eps) return 1;
  29. if(x < -eps) return -1;
  30. return 0;
  31. }
  32.  
  33. signed main() {
  34. int n;cin >> n;
  35. p a[n];
  36. for(int i = 0; i < n; i++){
  37. cin >> a[i].x >> a[i].y;
  38. }
  39. ll s = 0;
  40. for(int i = 1; i < n - 1; i++){
  41. s += cross(vec(a[0], a[i]), vec(a[0], a[i + 1]));
  42. cout << cross(vec(a[0], a[i]), vec(a[0], a[i + 1])) << endl;
  43. }
  44. cout << s;
  45. }
Success #stdin #stdout 0.01s 5320KB
stdin
100
-7 -19
91 77
100 100
64 60
-11 -1
80 87
69 95
5 46
37 46
25 38
-40 14
-11 35
0 33
-28 54
-19 62
25 84
13 87
-4 87
-16 73
-1 96
-44 75
-24 79
-59 18
-75 72
-54 31
-43 97
-100 100
-97 91
-52 -1
-68 15
-49 -14
-2 -9
-36 -24
-62 -9
-25 -53
-48 -21
-20 -59
-61 -12
-41 -65
-56 -52
-77 -17
-62 -73
-84 -25
-77 -15
-83 49
-93 -20
-88 59
-92 42
-100 50
-94 3
-100 -100
-93 -79
-83 -97
-51 -100
-52 -59
-44 -75
-38 -58
-46 -83
-24 -88
7 -43
97 1
61 -23
92 -13
92 -43
81 -40
84 -42
32 -42
19 -54
52 -43
81 -50
79 -85
69 -58
19 -60
-11 -72
9 -66
26 -77
28 -89
40 -71
47 -98
97 -100
97 -21
100 -100
96 37
79 16
98 57
26 -14
41 -6
46 -1
94 0
84 -5
20 -18
80 -6
21 -21
26 -21
-27 -71
28 -2
74 56
25 0
29 16
16 -1
stdout
1390
4
1594
-1990
1862
3572
-2080
428
2937
-1650
-586
1603
-825
-3828
1332
1802
1230
-1587
4819
-2028
4467
-2216
877
-3652
6504
480
3330
-432
1123
-445
265
-565
2050
-1358
1614
-2251
2722
-1132
-2408
3890
-3828
-728
-4456
5924
-6789
1689
-192
3957
9093
-1386
2148
2724
-1885
1040
-293
463
1603
1374
2776
-1776
804
-2970
33
-113
-1196
-767
1441
283
-3142
1662
-2102
-1542
1036
623
-280
1470
-905
3842
8216
-8210
14335
-1211
2861
-1983
189
175
-811
-315
-287
264
-538
10
-1756
1480
1248
-861
436
-157
43582