1010 - ++j; } vn = j; return 1; } inline double calc(Point...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
#include<iostream> #include<cmath> // Wrong Answer. using namespace std; enum { SIZ = 1008, }; const double eps = 1e-5; struct Point { double x,y; }; int n, vn; Point p[SIZ]; return (o.x-s.x)*(e.y-o.y) - (o.y-s.y)*(e.x-o.x); } { if ((min(a.x,b.x)>max(c.x,d.x)) || (min(c.x,d.x)>max(a.x,b.x)) || (min(a.y,b.y)>max(c.y,d.y)) || (min(c.y,d.y)>max(a.y,b.y))) return false; if ((multiply(a,b,c)*multiply(a,b,d)>0) || (multiply(c,d,a)*multiply(c,d,b)>0)) return false; return true; } return fabs(b.x-a.x) < eps & fabs(b.y-a.y) < eps; } int readIn(){ return 0; int j = 0; for(int i=0;i<n;i++){ scanf("%lf%lf",&p[j].x,&p[j].y); if (j==0 || !samepoint(p[j-1], p[j]))
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ++j; } vn = j; return 1; } inline double calc(Point &amp;s, Point &amp;e){ double ret; ret = s.x * e.y - s.y*e.x; ret /= 2; return ret; } int fun(){ if(n &lt; 3 || vn != n){ return -1; } double area = 0, t; for(int i=0;i&lt;n-1;i++){ for(int j=i+2;j&lt;n-1;j++){ if(interseg(p[i], p[i+1], p[j], p[(j+1)])){ return -1; } } } for(int i=1;i&lt;n-2;i++){ if(interseg(p[n-1],p[0], p[i], p[i+1])){ return -1; } } for(int i=0;i&lt;n-1;i++){ t = calc(p[i], p[i+1]); area += t; } t = calc(p[n-1], p[0]); area += t; if (area &lt; eps) area = fabs(area); printf(&quot;%.2lf\n&quot;, area); return 0; } int main(){ int tst = 0; while(readIn() &gt; 0){ if (tst) printf(&quot;\n&quot;); printf(&quot;Figure %d: &quot;, ++tst); if (fun() &lt; 0) printf(&quot;Impossible\n&quot;); } return 0; }...
View Full Document

Page1 / 2

1010 - ++j; } vn = j; return 1; } inline double calc(Point...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online