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

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

Hi there. I've been trying to solve http://www.spoj.com/problems/AKBAR/ for some time, but the only thing I can seem to come up with is starting a BFS from each of the soldiers as the source until the soldier's strength depth. However, that approach gives me a TLE. Any help regarding how to solve this problem would be appreciated. Thanks.

Here's the code for my approach that I tried (TLE): https://gist.github.com/paramsingh/81d728295e6bd01860a0

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

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

say ALLAHU AKBAR and problem will solve itself.

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

using memset in lines 39+40 gave you the TLE

you don't need to do it for every soldier, if any city is previously visited by another soldier, then the flag turns false...

remember that "every city is protected by one and only one soldier.According to Akbar , this is the optimum placement."

if you need more help, just tell me ^_^

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

.

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

I have been trying the question for a day now. Can someone please tell me what is wrong in this solution? I don't want to put up a blog about this. So whoever sees this comment please help me. I would really appreciate it.

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

    Try these changes maybe:

    1. Line 13 - parent[node] = -1; to parent[node] = node;
    2. Line 25 - parent[next_node] = cur_node; to parent[next_node] = par[cur_node];
    3. Line 28 - else if(strength[next_node] != strength[cur_node] - 1 && parent[cur_node] != parent[next_node]) to else if(parent[cur_node] != parent[next_node])
    4. Line 67 - if(visited[i] == -1) to if(!visited[i])
    
»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Can someone please see my solution. I'm getting a WA. This is the link https://ideone.com/hnGtXy

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

please help me with the same problem, why my solution getting WA??

MY_Solution

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