P25475 [AtCoder] [ABC016D] One-stroke Cut
普及+
题目描述

Problem Description

Takahashi has become able to cut wooden boards with a karate chop as a result of his training. Given a line segment representing the trajectory of the karate chop and a polygon representing the shape of the board, determine how many pieces the board is cut into.

Input Format

The input is given from the standard input in the following format:

$ A_x $ $ A_y $ $ B_x $ $ B_y $ $ N $ $ X_1 $ $ Y_1 $ $ X_2 $ $ Y_2 $ : $ X_N $ $ Y_N $

  • The first line contains the coordinates of the endpoints of the line segment $ A_x, A_y, B_x, B_y $ separated by spaces.
  • The second line contains the number of vertices of the polygon $N\ (3≦N≦100)$.
  • The next $ N $ lines contain the coordinates $ X_i, Y_i $ of each vertex separated by spaces.
  • The coordinates given in the input are integers between -1000 and 1000.

The line segment and polygon given in the input satisfy the following properties:

  • The vertices of the polygon are given in counterclockwise order.
  • The vertices of the polygon are at least 0.1 units away from the line segment.
  • The endpoints of the line segment are at least 0.1 units away from the polygon.
  • The endpoints of the line segment are outside the polygon.
  • No three consecutive vertices of the polygon are collinear.

Thus, the following inputs will not be given:

  • A, B: The vertices of the polygon are on the line segment.
  • C: The endpoints of the line segment are on the edge of the polygon.
  • D: The edge of the polygon overlaps with the line segment.
  • E: The endpoints of the line segment are inside the polygon.

Output Format

Output the number of pieces the board is cut into. End the output with a newline.

Sample Input and Output

Sample Input #1

-2 0 2 0
4
1 1
-1 1
-1 -1
1 -1

Sample Output #1

2

Sample Input #2

-3 1 3 1
8
2 2
1 2
1 0
-1 0
-1 2
-2 2
-2 -1
2 -1

Sample Output #2

3

Notes/Hints

None

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
-2 0 2 0 4 1 1 -1 1 -1 -1 1 -1
样例输出
2