有向面积裸题
所有有向三角形面积加起来就行
Code:
1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 #include<cmath> 5 #include<queue> 6 #include<iostream> 7 #define ms(a,b) memset(a,b,sizeof a) 8 #define rep(i,a,n) for(int i = a;i <= n;i++) 9 #define per(i,n,a) for(int i = n;i >= a;i--) 10 #define inf 2147483647 11 using namespace std; 12 typedef long long ll; 13 typedef double D; 14 #define eps 1e-8 15 ll read() { 16 ll as = 0,fu = 1; 17 char c = getchar(); 18 while(c < '0' || c > '9') { 19 if(c == '-') fu = -1; 20 c = getchar(); 21 } 22 while(c >= '0' && c <= '9') { 23 as = as * 10 + c - '0'; 24 c = getchar(); 25 } 26 return as * fu; 27 } 28 //head 29 #define P point 30 struct point { 31 D x,y; 32 point(){} 33 point(D X,D Y):x(X),y(Y){} 34 D len() {return sqrt(x*x+y*y);} 35 D tan() {return y/x;} 36 D sin() {return len() / y;} 37 D cos() {return len() / x;} 38 void print() {printf("%.2lf %.2lf ",x,y);} 39 friend inline point operator + (const point &a,const point &b) { 40 return point(a.x+b.x,a.y+b.y); 41 } 42 friend inline point operator - (const point &a,const point &b) { 43 return point(a.x-b.x,a.y-b.y); 44 } 45 //放缩 46 friend inline point operator * (const point &a,const D &b) { 47 return point(a.x*b,a.y*b); 48 } 49 //叉积 50 friend inline D operator * (const point &a,const point &b) { 51 return a.x*b.y-a.y*b.x; 52 } 53 //点积 54 friend inline D operator / (const point &a,const point &b) { 55 return a.x*b.x+a.y*b.y; 56 } 57 }; 58 struct line { 59 D k,b; 60 void init(point x,point y) { 61 k = (y.y-x.y)/(y.x-x.x); 62 b = x.y - k * x.x; 63 } 64 D YY(D X) {return k*X+b;} 65 D XX(D Y) {return (Y-b)/k;} 66 }; 67 struct yuan { 68 D r,x,y; 69 yuan(){} 70 yuan(int R,int X,int Y):r(R),x(X),y(Y){} 71 }; 72 73 bool ONSEG(point a,point b,point p) { 74 return ((a-b).len() == (a-p).len() + (p-b).len()); 75 } 76 D TRIAREA(point a,point b,point c) { 77 return ((a-b)*(a-c)) / 2.0; 78 } 79 #define ONLINE(a,b,c) (((a-b)*(a-c)) == 0) 80 81 #define sign(x) (x) > 0 ? 1 : ((x) < 0 ? -1 : 0) 82 // 1 0 -1 83 // 锐 直 钝 84 int ANGDIR(point a,point b,point p) { 85 D ans = (p-a)*(p-b); 86 return sign(ans); 87 } 88 89 D dis(point a,point b,point p) { 90 if(ANGDIR(b,p,a) == -1) return (p-a).len(); 91 if(ANGDIR(a,p,b) == -1) return (p-b).len(); 92 return ((p-a)*(p-b)) / (a-b).len(); 93 } 94 D dis(point a,line l) { 95 return (l.k * a.x - a.y + l.b) / sqrt(l.k*l.k+1); 96 } 97 98 int cross(P a,P b,P c,P d) { 99 if(ONLINE(a,b,c) ^ ONLINE(a,b,d)) return 1; 100 if(ONLINE(c,d,a) ^ ONLINE(c,d,b)) return 1; 101 if(ONLINE(a,b,c) & ONLINE(a,b,d)) return -1; 102 if(ONLINE(c,d,a) & ONLINE(c,d,b)) return -1; 103 D J1 = ((c-d)*(c-a)) * ((c-d)*(c-b)); 104 D J2 = ((a-b)*(a-c)) * ((a-b)*(a-d)); 105 if(J1 < 0 && J2 < 0) return 1; 106 return 0; 107 } 108 109 point Cross(point a,point b,point c,point d) { 110 if(ONLINE(a,b,c)) return c; 111 if(ONLINE(a,b,d)) return d; 112 if(ONLINE(c,d,a)) return a; 113 if(ONLINE(c,d,b)) return b; 114 D S1 = (a-c)*(a-d),S2 = (b-d) * (b-c); 115 point tmp = (b-a) * (S1 / (S1+S2)); 116 return a + tmp; 117 } 118 //CP 119 const int N = 10005; 120 point p[N]; 121 int main() { 122 while(1) { 123 int n = read(); 124 if(!n) return 0; 125 rep(i,1,n) scanf("%lf %lf",&p[i].x,&p[i].y); 126 D res = 0.0; 127 rep(i,1,n) (i ^ n) ? res += p[i] * p[i+1] : res += p[n] * p[1]; 128 printf("%.0lf ",fabs(res) / 2.0); 129 } 130 }