Блог пользователя kingofnumbers

Автор kingofnumbers, 11 лет назад, По-английски

Hello!

This is to remind you about second round of Croatian open competition in informatics will be held tomorrow Saturday 07.11.2015. 14:00 GMT/UTC

link for the contest: COCI

let's discuss the problems after the contest ends.

Good luck and have fun!

UPD: results are out!

  • Проголосовать: нравится
  • +68
  • Проголосовать: не нравится

»
11 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Interesting problems.

How to solve VUDU ?

»
11 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

How to solve SAVEZ?

»
11 лет назад, скрыть # |
 
Проголосовать: нравится +23 Проголосовать: не нравится

Did anyone solve F (drzava)? I could only come up with a conceptual solution using Delaunay triangulation (to compute euclidean minimum spanning tree). That can't be the intended solution though, right?

  • »
    »
    11 лет назад, скрыть # ^ |
     
    Проголосовать: нравится +5 Проголосовать: не нравится

    I tried to use kd-tree, but it works too slow even on random tests. Maybe in C++ it would be faster.

  • »
    »
    11 лет назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится +7 Проголосовать: не нравится

    One observation is that we never need more than K closest neighbours of the city (is it even correct? I only had 30 minutes to solve this task, so I didn't have much time to prove things). What I did is I took K closest cities by X, K closest cities by Y, and then merged the two lists and took K closest cities overall.

    Then you can do binary search for the squared distance, finding the connected components using only edges found above, and trying to find solution for the problem for each connected component separately.

    This works in N * K * log(MAX_DIST^2). Could still be too slow for 1 second, not sure.

    Edit: looks like this solution is not fast enough, or my implementation is slow. 96 points

    • »
      »
      »
      11 лет назад, скрыть # ^ |
       
      Проголосовать: нравится +15 Проголосовать: не нравится

      Pardon me, but could you elaborate on the "K closest cities by X, K closest cities by Y" part?

      I do understand that no more than k cities are necessary (pigeonhole principle) — but how does taking the k closest cities by x/y help?

      Consider the following points, with k = 2:

      0 0
      0 100
      0 101
      100 0
      101 0
      1 1
      2 2
      

      When inspecting (0,0) the k "closest" (in your x/y kind of sense) ones are the ones with the other coordinate being  ≥ 100. Here (1/1) and (2/2) should be taken, right?

      I believe I'm missing something really obvious here. Still, would you mind to explain? :)

  • »
    »
    11 лет назад, скрыть # ^ |
     
    Проголосовать: нравится +18 Проголосовать: не нравится

    Here's my solution, which receives full points after a small bug-fix:

    We binary search on D, so now we need to solve the problem of finding whether a given value of D works. This is in two parts: joining with union-find all points within distance D, and then applying knapsack to each component to test if some subset adds to 0 mod K.

    Part 1: Scan by x-value, maintaining a set sorted by y-value of all points with x-value at most D behind the leading line. Now for each point (a,b) in our scan, we iterate in the set through all points in this set with y-value in (b-D,b+D), and join to (a,b) all points within distance D. These are the points in the rectangle [a-d,a]x[b-D,b+D]. Note that by Pigeonhole, if we ever find a component of size at least K, we may stop and return a YES. This short-circuiting means (I think) that there can only be ~180 points in this box without more than K points lying in close proximity, and in most cases there should be much less.

    Part 2 modulo knapsack is quite easy, so of course this is where I made a bug.

    This solution is O(N*K*log(MAX_DIST)) but runs in less than 0.5 seconds on the test data.

»
11 лет назад, скрыть # |
 
Проголосовать: нравится +20 Проголосовать: не нравится

What was the point of 64MB memory limit in SAVEZ? It made usage of data structures hard and the only option was to use hashing — which is more boring than "real" string algorithms.

»
11 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Inclusion&Exclusion Principle + BitMask in problem B?

»
11 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Artur is geometry?

»
11 лет назад, скрыть # |
 
Проголосовать: нравится +8 Проголосовать: не нравится

for third problem , what is neatest way (and bug-free) to check which segment is above the other between two segments (or stating that no one is above the other)

many people got WA on this problem, and I think most of them failed because of bug in that part of their codes

  • »
    »
    11 лет назад, скрыть # ^ |
    Rev. 3  
    Проголосовать: нравится 0 Проголосовать: не нравится

    I think it's not that neat, but let me share my solution:

    I first check if their projections on x axis intersect. If not, then they don't block each other. Then I think them as lines instead of line segments and find their equations. Then I choose the bigger one of left ends of segments as common x value that both have y values. I plug that common x into their equations. The line segment with the less value is the one which blocks the other, so we should remove it first. The only tricky situation is when a line segment doesn't have a slope. In that case, instead of using equation, we can use any value between y1 and y2 of that line segment.

    My code

  • »
    »
    11 лет назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится 0 Проголосовать: не нравится

    Maybe your algorithm is still correct. But some ARTUR test cases (e.g 10a) make the sticks touch each others at beginning. Therefore, the topological order determination make WA. I already send a clarification and hope for their correction of test data

  • »
    »
    11 лет назад, скрыть # ^ |
     
    Проголосовать: нравится +3 Проголосовать: не нравится
    double solvey(int p, int x) {
      if (x1[p] == x2[p]) {
        return min(y1[p], y2[p]);
      }
      return 1.0 * (y2[p] - y1[p]) / (x2[p] - x1[p]) * (x - x1[p]) + y1[p];
    }
    bool covers(int p, int q) {
      // requirement: x1[p] <= x2[p] and x2[p] <= x2[q]
      // x does not overlap
      if (min(x2[p], x2[q]) < max(x1[p], x1[q])) return false;
      int z = min(x2[p], x2[q]);
      double yp = solvey(p, z);
      double yq = solvey(q, z);
      return yp < yq;
    }
    
»
11 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

What do you think is the problem of my solution for SAVEZ?

It gets WA on 1C.

»
11 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

What is SIGABRT?