题目链接:POJ 3805
Problem Description
Numbers of black and white points are placed on a plane. Let’s imagine that a straight line of infinite length is drawn on the plane. When the line does not meet any of the points, the line divides these points into two groups. If the division by such a line results in one group consisting only of black points and the other consisting only of white points, we say that theline “separates black and white points”.
Let’s see examples in Figure 3. In the leftmost example, you can easily find that the black and white points can be perfectly separated by the dashed line according to their colors. In the remaining three examples, there exists no such straight line that gives such a separation.
In this problem, given a set of points with their colors and positions, you are requested to decide whether there exists a straight line that separates black and white points.
Input
The input is a sequence of datasets, each of which is formatted as follows.
n m x1 y1 . . . xn yn xn+1 yn+1 . . . xn+m yn+m
The first line contains two positive integers separated by a single space; n is the number of black points, and m is the number of white points. They are less than or equal to 100. Then n + m lines representing the coordinates of points follow. Each line contains two integers xi and yi separated by a space, where (xi, yi) represents the x-coordinate and the y-coordinate of the i-th point. The color of the i-th point is black for 1 <= i <= n, and is white for n + 1 <= i <= n + m.
All the points have integral x- and y-coordinate values between 0 and 10000 inclusive. You can also assume that no two points have the same position.
The end of the input is indicated by a line containing two zeros separated by a space.
Output
For each dataset, output “YES” if there exists a line satisfying the condition. If not, output “NO”. In either case, print it in one line for each input dataset.
Sample Input
1 | 3 3 |
Sample Output
1 | YES |
Solution
题意
平面上有一些白点和黑点,问是否存在一条直线能把两类点分开。
题解
模板题。
详见 UVA 10256 The Great Divide (判断凸包相交)
Code
1 |
|