Tags » BF's

Bowling For Soup - Live at the O2 Academy, Sheffield + Interview

Two and a half years after bidding farewell to the UK, Bowling For Soup were back in Sheffield for another round! With hits including ‘Emily’, ‘1985’, ‘High School Never Ends’ and ‘Girl All The Bad Guys Want’ mixed with non-stop joking around, the band performed an incredibly memorable performance than the Steel City crowd won’t be forgetting any time soon! 1,408 more words

Sheffield

BFS Summary

I. Tree related
103. Binary Tree Zigzag Level Order Traversal
102. Binary Tree Level Order Traversal
107. Binary Tree Level Order Traversal II
199. Binary Tree Right Side View… 184 more words

BFS

Spoj - THE WEIRD STAIRCASE

Problem link : http://www.spoj.com/problems/STAR3CAS/

Idea :

Simple BFS.

♦Be careful about the upper/lower limits.


#include <bits/stdc++.h>
using namespace std;

vector<int>edge, cost;

int bfs(int dst)
{
int d;
for(int i = 0;i<1000;i++) d[i] = INT_MAX;
queue<int>q;
q.push(0);
d[0] = 0;
while(!q.empty()){
int u = q.front();q.pop();
int ucost = d[u];
for(int i = 0;i<edge[u].size(); i++){
int v = edge[u][i], vcost = cost[u][i] + ucost ;
if(d[v]>vcost){
d[v] = vcost;
q.push(v);
}
}
}
return d;

}

int main()
{

int t;
scanf("%i", &t);
for(int j = 0;j<t; j++)
{
int n;
scanf("%i", &n);
int a;
for(int i = 0;i<n;i++){
scanf("%i", a+i);
}
for(int i = 0;i<n ; i++)
{
if(a[i]>=0){
if(i+1<=n)
{ edge[i].push_back(i+1);
cost[i].push_back(1);
}
if(i+a[i]<=n)
{ edge[i].push_back(i+a[i]);
cost[i].push_back(1);
}
}
else if(a[i]<0){
if(i+1<=n)
{ edge[i].push_back(i+1);
cost[i].push_back(1);
}
if(i+a[i]>=0)
{
edge[i].push_back(i+a[i]);
cost[i].push_back(1);
}
}
}
printf("%i\n", bfs(n));
for(int i = 0;i<1000;i++){edge[i].clear(); cost[i].clear();}
}
return 0;
}
BFS

Light Oj 1009 - Back to Underworld

Problem link: http://lightoj.com/volume_showproblem.php?problem=1009

Idea:

In my code I denoted Vampires and Lykans by two different colors, black and red. At first all
nodes are unassigned. Then I select an unassigned node and make it black (or red). 234 more words

BFS

Light OJ 1174-Commandos

Problem link : http://lightoj.com/volume_showproblem.php?problem=1174
Idea :
  •  Firstly start from the building ‘s’ and go to the i’th building
  • Secondly from the i’th building, go to building d…
  • 261 more words
BFS

The Great Gatsby:The Tragedy

In chapter 7 of the Great Gatsby, the rich conquer the poor emerges over numerous scenes. “‘I hear you fired all your servants.”I wanted somebody who wouldn’t gossip. 255 more words

#BFS

Graph BFS

Summary

BFS
  • BFS = queue+hashtable
  • always perform enqueue and mark visited together
  • BFS is faster then union find. Consider using it first even if involves sets…
  • 1,966 more words
Leetcode