removed1's blog

By removed1, 22 months ago, translation, In English

Problem A.

The constraint that edges of each flagstone much be parralel to edges of the square allows to analyze X and Y axes separately, that is, how many segments of length 'a' are needed to cover segment of length 'm' and 'n' -- and take product of these two quantities. Answer = ceil(m/a) * ceil(n/a), where ceil(x) is the least integer which is above or equal to x. Using integers only, it is usually written as ((m+a-1)/a)*((n+a-1)/a). Note that answer may be as large as 10^18, which does not fit in 32-bit integer.

Most difficulties, if any, contestants had with data types and operator priority, which are highly dependant on language used, so they are not covered here.

Problem B.

Let each letter representation of column number be associated with integer in radix-26, where 'A' = 0, 'B' = 1 ... 'Z'=25. Then, when converting letter representation to decimal representation, we take associated integer and add one plus quantity of valid all letter representations which are shorter than letter representation being converted. When converting from decimal representation to letter representation, we have to decide how many letters do we need. Easiest way to do this is to subtract one from number, then quantity of letter representation having length 1, then 2, then 3, and so on, until next subtraction would have produced negative result. At that point, the reduced number is the one which must be written using defined association with fixed number  of digits, with leading zeroes (i.e. 'A's) as needed.

Note that there is other ways to do the same which produce more compact code, but they are more error-prone as well.

Problem C.

The points can be vertices of regular N-polygon, if, and only if, for each pair, difference of their polar angles (as viewed from center of polygon) is a multiple of 2*pi/N. All points should lie on the circle with same center as the polygon. We can locate the center of polygon/circle [but we may avoid this, as a chord (like, say, (x1,y1)-(x2,y2)) is seen at twice greater angle from center, than it is seen from other point of a cricle (x3,y3)]. There are many ways to locate center of circle, the way I used is to build midpoint perpendiculares to segments (x1,y1)-(x2,y2) and (x2,y2)-(x3,y3) in form y = a*x + b and find their intersection. Formula y = a*x + b has drawback that it cannot be used if line is parallel to y, possible workaround is to rotate all points by random angle (using formulae x' = x*cos(a) - y*sin(a), y' = y*cos(a) + x*sin(a) ) until no segments are horizontal (and hence no perperdiculares are vertical).

After the coordinates of the center are known, we use fancy function atan2, which returns angle in right quadrant: a[i] = atan2(y[i]-ycenter, x[i]-xcenter)

Area of  regular polygon increases with increasing N, so it is possible just to iterate through all possible values on N in ascending order, and exit from cycle as first satisfying N is found.

Using sin(x) is makes it easy: sin(x) = 0 when x is mutiple of pi. So, for points to belong to regular, N-polygon,

sin( N * (a[i]-a[j]) /2 )=0

because of finite precision arithmetic, 

fabs( sin( N * (a[i]-a[j]) /2 ) ) < eps


 
 
 
 

 
21 month(s) ago, #
  Vote: I like it +1 Vote: I do not like it
You can use TeX for the mathematical formulas.
 
21 month(s) ago, #
  Vote: I like it 0 Vote: I do not like it
Problem B.
I can't pass Test case 6.
I don't konw why? Isn't there a test case like:
Input: R001C001
Ouput: 00A001
?
   
14 months ago, #
  Vote: I like it 0 Vote: I do not like it
Who can give me the data on test 6?
Why I always get WA、 
  •  
    13 months ago, # ^
      Vote: I like it 0 Vote: I do not like it
    test 6 is very big (1000 lines)
    try to check this test instead:

    13
    R1C17
    R1C18
    R1C19
    R1C20
    R1C21
    R1C22
    R1C23
    R1C24
    R1C25
    R1C26
    R1C27
    R1C28
    R1C29

    after passing this I got AC.
    •  
      12 months ago, # ^
        Vote: I like it 0 Vote: I do not like it
      This is what I got,

      Q1
      R1
      S1
      T1
      U1
      V1
      W1
      X1
      Y1
      Z1
      AA1
      AB1
      AC1

      Which i believe is the correct solution. But it still wouldnt pass test 6 :(