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

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

Don't forget that Google Code Jam Round 1C will be starting in less then 28 hours !! Visit the Code Jam site and get ready to compete.

Let's discuss solutions here after the contest. I would like to know other peoples approaches.

Good Luck :)

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

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

C-large?

  • »
    »
    10 лет назад, скрыть # ^ |
     
    Проголосовать: нравится +19 Проголосовать: не нравится
    int j, p, s, k;
    cin >> j >> p >> s >> k;
    vector< vector< int > > res;
    int diff = min(s, k);
    for (int i1 = 0; i1 < j; ++i1) {
        for (int i2 = 0; i2 < p; ++i2) {
            for (int l = 0; l < diff; ++l) {
                int i3 = (i1 + i2 + l) % s;
                res.push_back({i1 + 1, i2 + 1, i3 + 1});
            }
        }
    }
    
    • »
      »
      »
      10 лет назад, скрыть # ^ |
       
      Проголосовать: нравится +3 Проголосовать: не нравится

      you are genius! my solution of C_small is about 100 lines:)

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

      Can you please explain what you are doing? You have chosen diff as min(s, k), so any pair of (jacket, pants) will not occur more than 'diff' times. But what about the (jacket, shirt) and (shirt, pants) pairs? I did not understand how this guarantees that those pairs will also occur <= k times.

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

        It's easy to prove that for arbitrary present pair (i1, i3) of jacket and shirt and every l in range [0;diff) there is at most one valid pants i2, i.e. satisfying constraints i3 ≡ (i1 + i2 + l)(mods), because s ≥ p ≥ j. That's why we get no more than diff ≤ k pairs (i1, i3).

        The same holds for arbitrary present pair (i2, i3).

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

is the solution to problem A: always remove first two biggest numbers of senators?

nvm source code removed

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

It was so frustrating that I was debugging my B for more than 20 minutes just because I was printing extra spaces between the elements. =/

Reminds me of how stupid I can be at times.

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

C-small?

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

Was brute force able to pass for C small?

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

1B rank — 1206
1C rank — 1149

i think i will never make to top 1000 :(

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

What is the solution for B?

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

    The main idea is following: let's build a graph, where there is an edge V -> U (for all V, U, V < U). It's easy to see, that in this graph the total amount of ways to get from point 1 to point N is 2 ^ (N — 2) (because we can choose any subset of vertices from 2 to N — 1 to go through). Now, if we delete an edge 1 -> V0, we'll lose 2 ^ (N — V0 — 1) ways. Thus, we can use greedy algorithm : iterate over all V0 (from 2 to N — 1) and try to remove an edge (1 -> V0).

    Code : http://pastebin.com/WrGmMdtU

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

      We can also not to remove, but add the edges (1 -> K) using the binary representation of (m - 1)
      (edge (1 -> B) that gives us 1 way I took in any case).

      Code: http://paste.ubuntu.com/16298555/

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

        Yeah and I kept adding edges from i to j for all i < j in a loop going through all j for each i from 2 to B-1 until I had gone above M, and then I used the binary representation of the difference between how many paths there currently was (which I had kept count of) and M, to delete the edges between the bits that are on in the difference and B-1, it follows the same kind of logic to prove it works.

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

          Your solution seems to be unnecessarily complicated. The main reason for me to use binary representation was to avoid greediness. Since every number has exactly one binary representation, I can iterate from 0 to B-3 or vise versa and get the solution anyway.

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

            I agree that yours which is also the way of the contest analysis is much more straight forward, I just came to the other one, and thought I'd share a similar but different approach :). I don't use anything that's greedy either though, I just keep adding edges until I'm past M and if it's not equal to M I use the binary representation of the difference to remove edges that will make the paths == M

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

    I did backtracking + dfs Basically kept adding edges using dfs as long as no. of paths was less than M If addition of new edge led to no of paths >M remove it and try others Keep count of no. of paths starting at a particular bldg and ending at final building

    http://pastebin.com/MaKJBdGK

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

I accidentally deleted my input0 for 1st problem, so when I downloaded it again, it triggered input1 for the problem, so two incorrect solutions. Can anyone expain this? Anyway I finished with 1004 missing the cut by 20 seconds :(

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

That moment when your problem B fails due to ll maximum = 1 << (B-2); overflow that should've been ll maximum = 1ll << (B-2);

"luckily" I would only have placed around 1300 if I'd gotten it correct due to being slow, otherwise I would be punishing myself for that for a week :P.