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

Автор sore_loser, история, 9 лет назад, По-английски

Suppose, I have a matrix with N rows and M columns. I want to find the number that appears most along with their frequencies for each row and each column. If there are multiple such numbers, any of them will do.

For example, let the matrix be a 4*3 matrix like this:

9 4 4

5 4 2

1 3 1

1 1 2

then I will perform calculation in these four arrays as follows:

rowval = {4,2,1,1} [ith value denotes the number that appears most in ith row]

rowfrq = {2,1,2,2} [the number of time the the max value of ith row appears]

colval = {1,4,2} [ith value denotes the number that appears most in ith column]

colfrq = {2,2,2} [the number of time the the max value of ith column appears]

What will be the most efficient way of performing this calculation? N*M can be upto 10^6 and the values of the matrix can be upto 10^6 as well . I was thinking of using map, but cannot understand what the complexity will be. Of course if there is a better approach, please help :)

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

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

ongoing contest... Codechef february long challenge..

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

This is getting ridiculous. Almost every day some idiot (like you) asks about a problem from Codechef.

The big problem is that you ask about the simple ones. Please post questions about the hard ones :).

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

    thank you for your help. There are some dimwits (like you) who can't resist commenting shit which is enough to show that I am on the right path.

    And following that path, I have just solved the problem :v Thanks again for your help, dimwit :v Should have not bothered commenting which would have prevented me digging deeper into this approach, dimwit. Take a lesson from here for the future and try not to show off everywhere, dimwit :v