Listing: POLITIE.PAS const ni='Input.txt'; no='Output.txt'; mare=10000; type punct=record x,y:Longint end; camp=record u:Real; v:Integer end; lcamp=array[1..1000] of camp; var g:array[1..1000] of punct; gu:array[0..1000] of Real; c:lcamp; a:punct; i,j,k,m,n,crime,test:Integer; cgx,cgy,u,t:Real; procedure citeste; begin Assign(input,ni); Reset(input); Readln(n); for i:=1 to n do Readln(g[i].x,g[i].y); Readln(m) end; function det(a,b,c:punct):Longint; begin det:=a.x*b.y+b.x*c.y+c.x*a.y-a.y*b.x- b.y*c.x-c.y*a.x end; procedure init; begin cgx:=0; cgy:=0; for i:=1 to n do begin cgx:=cgx+g[i].x; cgy:=cgy+g[i].y; end; cgx:=cgx/n; cgy:=cgy/n; k:=0; gu[0]:=pi; for i:=1 to n do if Abs(cgx-g[i].x)<0.001 then if cgy<g[i].y then gu[i]:=Pi/2 else gu[i]:=3*Pi/2 else begin t:=(g[i].y-cgy)/(g[i].x-cgx); gu[i]:=Arctan(t); if cgx>g[i].x then gu[i]:=gu[i]+pi else if gu[i]<0 then gu[i]:=gu[i]+2*pi; if gu[i]<gu[k] then k:=i end; if k=n then i:=1 else i:=k+1; if k=1 then j:=n else j:=k-1; if gu[i]<gu[j] then begin i:=0; while i<n do begin Inc(i); c[i].u:=gu[k]; c[i].v:=k; if k=n then k:=1 else Inc(k) end; end else begin i:=0; while i<n do begin Inc(i); c[i].u:=gu[k]; c[i].v:=k; if k=1 then k:=n else Dec(k) end end end; procedure rezolva; begin init; crime:=0; Assign(output,no); Rewrite(output); for test:=1 to m do begin Dec(m); Readln(a.x,a.y); if Abs(cgx-a.x)<0.001 then if a.y>cgy then u:=Pi/2 else u:=3*Pi/2 else begin t:=(a.y-cgy)/(a.x-cgx); u:=Arctan(t); if a.x<cgx then u:=u+pi else if u<0 then u:=u+2*pi; end; if (u<=c[1].u) or (u>=c[n].u) then begin if det(a,g[c[n].v],g[c[1].v])>=0 then Inc(crime) end else begin i:=1; j:=n; while i<j-1 do if u>=c[(i+j) div 2].u then i:=(i+j) div 2 else j:=(i+j) div 2-1; j:=c[i+1].v; i:=c[i].v; if det(a,g[i],g[j])>=0 then Inc(crime) end end end; procedure scrie; begin Writeln(crime) end; Begin citeste; rezolva; scrie End. [cuprins] |