两条线段的两个端点坐标(x1,y1) (x2,y2) (x3,y3) (x4,y4)
b1=(y2-y1)*x1+(x1-x2)*y1
b2=(y4-y3)*x3+(x3-x4)*y3
D=(x2-x1)(y4-y3)-(x4-x3)(y2-y1)
D1=b2*(x2-x1)-b1*(x4-x3)
D2=b2*(y2-y1)-b1*(y4-y3)
交点(x0,y0)
x0=D1/D y0=D2/D
推导:http://www.cnblogs.com/dwdxdy/p/3230485.html
E. Covered Points
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
You are given nn segments on a Cartesian plane. Each segment's endpoints have integer coordinates. Segments can intersect with each other. No two segments lie on the same line.
Count the number of distinct points with integer coordinates, which are covered by at least one segment.