1081 - } bool checkInside(){ int i; int r = 0; if (N==1){...

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

View Full Document Right Arrow Icon
#include<iostream> using namespace std; enum { SIZ = 104, }; int N, M; struct Point { int x,y; }pnt[SIZ]; Point dot; if (a.y==b.y){ if (a.y==dot.y) return (dot.x>=min(a.x,b.x) & dot.x<=max(a.x,b.x)); return false; } return true; return true; if (a.y==dot.y||b.y==dot.y) return false; return (dot.y-b.y)*(a.x-dot.x) - (a.y-dot.y)*(dot.x-b.x) == 0 & dot.y>=min(a.y,b.y) && dot.y<=max(a.y,b.y); } if (a.y==b.y){ return 0; } if (a.y==dot.y){ if (a.x > dot.x) return 0; if (b.y>a.y){ return 0; } return 1; } if (b.y==dot.y){ if (b.x > dot.x) return 0; if (a.y > b.y) return 0; return 1; } double x = (a.y*b.x -b.y*a.x) + dot.y*(a.x-b.x); x /= (a.y-b.y); return (x<=dot.x & dot.y>=min(a.y,b.y) && dot.y<=max(a.y,b.y));
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: } bool checkInside(){ int i; int r = 0; if (N==1){ return (pnt[0].x==dot.x)&amp;&amp;(pnt[0].y==dot.y); }else if(N==2){ return online(pnt[0],pnt[1]); } for (i=0; i&lt;N; ++i){ if (online(pnt[i], pnt[(i+1)%N])){ return true; } else if (intersect(pnt[i], pnt[(i+1)%N])){ r = 1 - r; } } return r; } void fun(){ while(M--){ scanf(&quot;%d%d &quot;, &amp;dot.x, &amp;dot.y); if (checkInside()){ printf(&quot;Within\n&quot;); } else { printf(&quot;Outside\n&quot;); } } } int readIn(){ scanf(&quot;%d%d &quot;, &amp;N, &amp;M); if (N == 0) return N; for (int i=0; i&lt;N; ++i){ scanf(&quot;%d%d &quot;, &amp;pnt[i].x, &amp;pnt[i].y); } return N; } int main(){ int tst=0; while(readIn() &gt; 0){ if (tst++) printf(&quot;\n&quot;); printf(&quot;Problem %d:\n&quot;, tst); fun(); } return 0; }...
View Full Document

Page1 / 2

1081 - } bool checkInside(){ int i; int r = 0; if (N==1){...

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