What will happen if r=di,c=dj in your safe function,I think that is causing the error...
On Sat, Jul 23, 2011 at 8:29 PM, viswanath vellaiappan < viswanath.vellaiap...@gmail.com> wrote: > I agree with Shady on asking for algo for the problem but lets not be hard > on posting spoj question on spoj forum as these too involves algorithm (our > interest). > > @KK : Can you tell us the judging status you are hitting? (Wrong answer, > timeout??). > > > ~Viswanath. > > > On Sat, Jul 23, 2011 at 4:57 PM, shady <sinv...@gmail.com> wrote: > >> there's something called spoj forum, try posting it there.... >> secondly, ask whether ur algo is right or wrong, not the code >> >> >> On Sat, Jul 23, 2011 at 4:51 PM, KK <kunalkapadi...@gmail.com> wrote: >> >>> www.spoj.pl/problems/SHOP >>> Its a pretty easy Q... But m not able to figure out any silly mistake >>> in my prog.. plzz help >>> >>> #include<iostream> >>> #include<vector> >>> #include<map> >>> #include<queue> >>> >>> using namespace std; >>> >>> char a[26][26]; >>> int si, sj, di, dj, rows, cols; >>> >>> void BFS(vector< vector<int> > &v, int si, int sj, int rows, int >>> cols); >>> int safe(vector< vector<int> > &v, int r, int c, int current, int >>> rows, int cols); >>> >>> int main() >>> { >>> freopen("input.txt", "r", stdin); >>> freopen("output.txt", "w", stdout); >>> >>> int si, sj; >>> while(1) >>> { >>> cin >> cols >> rows; >>> >>> if(rows == 0 && cols == 0) >>> break; >>> >>> vector<int> row(26, INT_MAX); >>> vector< vector<int> > final(26, row); >>> >>> for(int i=0; i<rows; i++) >>> for(int j=0; j<cols; j++) >>> { >>> cin >> a[i][j]; >>> if(a[i][j] == 'S') >>> { >>> si = i; sj = j; >>> } >>> else if(a[i][j] == 'D') >>> { >>> di = i; dj = j; >>> a[i][j] = '0'; >>> } >>> } >>> >>> BFS(final, si, sj, rows, cols); >>> cout << final[di][dj] << endl; >>> >>> /* >>> for(int i=0; i<rows; i++) >>> { >>> for(int j=0; j<cols; j++) >>> cout << final[i][j] << " "; >>> cout << endl; >>> } >>> cout << endl; >>> */ >>> } >>> return 0; >>> } >>> >>> void BFS(vector< vector<int> > &v, int si, int sj, int rows, int cols) >>> { >>> pair<int, int> p; >>> queue< pair<int, int> > q; >>> >>> q.push(make_pair(si, sj)); >>> v[si][sj] = 0; >>> >>> while(!q.empty()) >>> { >>> p = q.front(); q.pop(); >>> int current = v[p.first][p.second]; >>> >>> if(safe(v, p.first+1, p.second, current, rows, cols)) >>> q.push(make_pair(p.first+1, p.second)); >>> >>> if(safe(v, p.first-1, p.second, current, rows, cols)) >>> q.push(make_pair(p.first-1, p.second)); >>> >>> if(safe(v, p.first, p.second+1, current, rows, cols)) >>> q.push(make_pair(p.first, p.second+1)); >>> >>> if(safe(v, p.first, p.second-1, current, rows, cols)) >>> q.push(make_pair(p.first, p.second-1)); >>> >>> } >>> } >>> >>> int safe(vector< vector<int> > &v, int r, int c, int current, int >>> rows, int cols) >>> { >>> if(r >= 0 && r < rows && c >= 0 && c < cols && a[r][c] != 'X') >>> { >>> if(v[r][c] > current + a[r][c] - '0') >>> { >>> v[r][c] = current + a[r][c] - '0'; >>> return 1; >>> } >>> >>> } >>> return 0; >>> } >>> >>> -- >>> You received this message because you are subscribed to the Google Groups >>> "Algorithm Geeks" group. >>> To post to this group, send email to algogeeks@googlegroups.com. >>> To unsubscribe from this group, send email to >>> algogeeks+unsubscr...@googlegroups.com. >>> For more options, visit this group at >>> http://groups.google.com/group/algogeeks?hl=en. >>> >>> >> -- >> You received this message because you are subscribed to the Google Groups >> "Algorithm Geeks" group. >> To post to this group, send email to algogeeks@googlegroups.com. >> To unsubscribe from this group, send email to >> algogeeks+unsubscr...@googlegroups.com. >> For more options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. >> > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algogeeks@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- *Regards,* *Piyush Kapoor,* *CSE-IT-BHU* -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.