题目描述
Farmer John has a brilliant idea for the next great spectator sport: Cow Steeplechase! As everyone knows, regular steeplechase involves a group of horses that race around a course filled with obstacles they must jump over. FJ figures the same contest should work with highly-trained cows, as long as the obstacles are made short enough.
In order to design his course, FJ makes a diagram of all the N (1 <= N <= 250) possible obstacles he could potentially build. Each one is represented by a line segment in the 2D plane that is parallel to the horizontal or vertical axis. Obstacle i has distinct endpoints (X1_i, Y1_i) and (X2_i, Y2_i) (1 <= X1_i, Y1_i, X2_i, Y2_i <= 1,000,000,000). An example is as follows:
--+------- -----+----- ---+--- | | | | --+-----+--+- | | | | | | | --+--+--+-+- | | | | |
FJ would like to build as many of these obstacles as possible, subject to the constraint that no two of them intersect. Starting with the diagram above, FJ can build 7 obstacles:
---------- ----------- ------- | | | | | | | | | | | | | | | | | | |
Two segments are said to intersect if they share any point in common, even an endpoint of one or both of the segments. FJ is certain that no two horizontal segments in the original input diagram will intersect, and that similarly no two vertical segments in the input diagram will intersect.
Please help FJ determine the maximum number of obstacles he can build.
给出N平行于坐标轴的线段,要你选出尽量多的线段使得这些线段两两没有交点(顶点也算),横的与横的,竖的与竖的线段之间保证没有交点,输出最多能选出多少条线段。
输入输出格式
输入格式:
* Line 1: A single integer: N.
* Lines 2..N+1: Line i+1 contains four space-separated integers representing an obstacle: X1_i, Y1_i, X2_i, and Y2_i.
输出格式:
* Line 1: The maximum number of non-crossing segments FJ can choose.
输入输出样例
输入样例#1:
3 4 5 10 5 6 2 6 12 8 3 8 5
输出样例#1:
2
Solution
网络流,正难则反,明显可以看出的是,我们可以把交叉的线段之间连边然后就可以求出最大匹配,这也就是我们需要去掉的线段的数目。一道入门题目?然而蒟蒻做了一个小时。。。
Code
#pragma comment(linker, "/STACK:1024000000,1024000000")#include #include #include #include #include #include #include #include #include #include