Editorial for COCI '06 Contest 2 #4 Sjecišta
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
Imagine that the polygon's vertices are labeled to consecutively. Consider a diagonal from vertex to some vertex . Vertices through are on one side of the diagonal, vertices through on the other. The diagonal intersects only those diagonals which have one vertex on one side and the other on the other side. Thus there are diagonals intersecting it.
We count all diagonals with one vertex being vertex and multiply the number of diagonals by (we could have labeled any vertex and would get the same result). We counted each intersection on one diagonal twice (once from each vertex on a single diagonal) and each intersection a total of four times (because it lies on two diagonals). Hence we divide the result by .
Comments