TriangleXor
SRM 587 · 2013-06-25 · by ir5
Problem Statement
You are given an
The objective in this problem is to calculate the area of the region (T[0] xor T[1] xor ... xor T[W]). (See Notes for a formal definition.) The figures below show the region (T[0] xor T[1] xor ... xor T[W]) for W=1,2,3,4,5,6.
Return the integer part of the area of the region.
Notes
- For sets of points A and B in the XY-plane, the set (A xor B) is defined as the set of all points that lie in exactly one of the sets A and B (i.e., points that belong to the union of A and B but don't belong to their intersection).
- If the exact area is A, the correct return value is floor(A), not round(A). In words: you should return the largest integer that is less than or equal to the exact area.
- The format of the return value was chosen to help you in case of small precision errors. The constraints guarantee that computing the correct area with absolute error less than 0.01 is sufficient to determine the correct return value. The author's solution is significantly more precise than that.
Constraints
- W will be between 1 and 70,000, inclusive.
- The difference between the exact area of the region and the nearest integer will be greater than 0.01.
1 Returns: 0
The exact area is 0.5.
2 Returns: 1
The area is approximately 1.33333.
3 Returns: 1
The exact area is 1.35.
4 Returns: 2
The area is approximately 2.62857. Note that the correct answer is 2, not 3.
5 Returns: 2
The area is approximately 2.13294.
Submissions are judged against all 60 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class TriangleXor with a public method int theArea(int W) · 60 test cases · 2 s / 256 MB per case