ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1241. Inlay Cutters

Hint
Posted by SkorKNURE 4 Nov 2010 03:03
Obviously the problem has many ways to be solved. But I think it is still a tricky one to implement. Don't think my way is short enough but forum doesn't offer any solution at all :-) I think that the description of my source which I sometimes write to certain solutions can help someone to get AC, so I'll leave it here...

/*
 * Let's consider all types of triangles can occure during the
 * cutting process. We can easily notice that there are only 2
 * such type: triangle with sides on 2 diagonal lines and 1
 * straight (vertical or horizontal) or vice-versa (1 and 2).
 * So we can count triangles of these two types separately
 * to get the answer. How can we do this? Let's "draw" our
 * cuts in 2d-array (n-1)x(m-1) and consider a single cell.
 * This cell can be crossed by vertical line from the left and
 * from the right, by horizontal - from top and down and by
 * diagonal - as main and secondary diagonals' directions.
 * So we can code 1 cell with 6-bit value where each bit
 * shows whether corresponding cut goes through the cell or not.
 * Then we can iterate each possible position of triangles
 * of both types on the plate and check whether this triangle really
 * placed here. Small plate size allows us to do this fast enough.
 * And finally, several tricks can be used here:
 *    1. To avoid all intersections located in the middle of any
 *       cell scale all plane in 2 times (multiply each coord by 2).
 *    2. Write only 2 prodecures for recognizing 1 and 2 type of
 *       triangles. Obviously each type can be rotated 4 times on
 *       the plane. Don't try to check these rotations. Simply
 *       make correct recognition of one of them and then solve
 *       problem 4 times rotating the whole plane. After that all
 *       triangles will be counted separalely and in correct way.
 */