Блог пользователя -is-this-fft-

Автор -is-this-fft-, история, 6 лет назад, По-английски

Sometimes we see problems where a seemingly naive algorithm — for example simple brute force — is actually the correct solution. Mostly, I mean problems where, due to some clever observations, the complexity of the brute force algorithm is greatly reduced.

For example, in a recent contest we had 1168B - Good Triple. You can notice that any string of length at least 9 contains a "good triple", which means a brute force is sufficient here and runs in $$$O(n)$$$.

Or 1028F - Make Symmetrical where you can notice that on any given circle, there are not too many lattice points.

Randomized input is also a good source of these. In 896C - Willem, Chtholly and Seniorious you can observe that after a bit of time, most adjacent elements of the array are equal and write something seemingly naive based on that.

What are some other examples of problems where a stupid brute force is actually the correct solution?

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

»
6 лет назад, # |
Rev. 4   Проголосовать: нравится 0 Проголосовать: не нравится

problem Ehab and Expected XOR Problem

my code complexity was $$$O(2^{2n})$$$ which passed fast because it finds next number with low number of iterations so actual runtime of the code wasn't slow

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Can you prove even that this solution produces maximal length, without using ideas from real solution?

»
6 лет назад, # |
  Проголосовать: нравится -16 Проголосовать: не нравится

1073D - Berland Fair brute force solution is correct because given cost reduces very fast on every iteration.

»
6 лет назад, # |
  Проголосовать: нравится +34 Проголосовать: не нравится

It often happens in problems where you need to print the answer with some precision. If something is unlikely to happen, don't compute it.

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

https://www.codechef.com/GW19MOS/problems/MEANPROB

This is from a ICPC regional. The bruteforce algorithm works

»
4 года назад, # |
  Проголосовать: нравится +15 Проголосовать: не нравится
  • Problems about merging small sets to large sets
  • Tree DP in $$$O(nk)$$$ time by iterating only until $$$min(subtreeSize[v], k)$$$.
  • $$$O(3^{n/3})$$$ clique: It looks like a simple branch-and-bound heuristic at first glance.
  • Problems with randomization: link. You can use similar tricks for smallest enclosing circles and Voronoi diagram.
»
4 года назад, # |
  Проголосовать: нравится +6 Проголосовать: не нравится

Maybe just for me but I came up with the solution of 1361F in half a minute.

PS: my real color is orange

»
4 года назад, # |
Rev. 3   Проголосовать: нравится -10 Проголосовать: не нравится

Because the problem setter is also stupid sometime.