fork download
  1. #include <stdio.h>
  2. int main(void){
  3. int x1,x2,y1,y2,nx,ny;
  4. int bef_pos=0,pos;
  5. int count=0;
  6. int n, i;
  7.  
  8. scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
  9. scanf("%d",&n);
  10. for(i=0;i<n;i++){
  11. scanf("%d %d",&nx,&ny);
  12. if(x1==x2) pos=nx-x1;
  13. else if(y1==y2) pos=ny-y1;
  14. if(bef_pos==0){ bef_pos=pos; continue;}
  15. if(bef_pos*pos<0) count++;
  16. if(bef_pos*pos!=0) bef_pos=pos;
  17. }
  18. if(count%2) count++;
  19. printf("%d",1+count/2);
  20.  
  21. return 0;
  22. }
Success #stdin #stdout 0s 2172KB
stdin
7 1 7 15
12
3 3
12 3
12 8
6 8
6 9
12 9
12 11
4 11
4 6
8 6
8 4
3 4
stdout
4