The Code-Bin
Links
Home
Add your code!
All Listings
About
Latest Entry
Featured Scripts
Author's Website
Latest Entries
FFMPEG Thumbnail Scr...
PHP, 0.8KB
Jul. 29, 10:24pm
John
Z80 Assembler, 190 bytes
Feb. 17, 3:36am
John
Z80 Assembler, 176 bytes
Sep. 13, 2:19am
John
Z80 Assembler, 77 bytes
Sep. 13, 2:18am
John
Z80 Assembler, 209 bytes
Sep. 13, 2:17am
10653 - Bombs! NO they are Mines!!
Posted by: 10653 | April 15, 2011 @ 12:56pm
C++ Code
[
Download
]
#include<iostream> #include<queue> #include<cstdio> #define M 1005 using namespace std; int color[M][M],D[M][M]; int main() { queue<int>Q; int r,c,rn,cn,x,y,i,j,sx,sy,dx,dy,tx,ty; freopen("in.txt","r",stdin); while(scanf("%d%d",&r,&c)&&(r|c)) { for(i=0;i<r;i++) for(j=0;j<c;j++) color[i][j]=0; scanf("%d",&rn); for(i=0;i<rn;i++) { scanf("%d%d",&x,&cn); for(j=0;j<cn;j++) { scanf("%d",&y); color[x][y]=1; } } scanf("%d%d%d%d",&sx,&sy,&dx,&dy); color[sx][sy]=1,D[sx][sy]=0; Q.push(sx); Q.push(sy); while(!Q.empty()) { x=Q.front();Q.pop(); y=Q.front(),Q.pop(); //Check Backward if(x>0) { tx=x-1; ty=y; if(!color[tx][ty]) { D[tx][ty]=D[x][y]+1; if(tx==dx && ty==dy)break; Q.push(tx);Q.push(ty); color[tx][ty]=1; } } //Check Forward if(x<c) { tx=x+1; ty=y; if(!color[tx][ty]) { D[tx][ty]=D[x][y]+1; if(tx==dx && ty==dy)break; Q.push(tx);Q.push(ty); color[tx][ty]=1; } } //Check Upward if(y>0) { tx=x; ty=y-1; if(!color[tx][ty]) { D[tx][ty]=D[x][y]+1; if(tx==dx && ty==dy)break; Q.push(tx);Q.push(ty); color[tx][ty]=1; } } //Check Downward if(y<r) { tx=x; ty=y+1; if(!color[tx][ty]) { D[tx][ty]=D[x][y]+1; if(tx==dx && ty==dy)break; Q.push(tx);Q.push(ty); color[tx][ty]=1; } } color[x][y]=2; } while(!Q.empty()) Q.pop(); printf("%d\n",D[dx][dy]); } return 0; }
Syntax Highlighting
[
Open in new window
]
Author Comments
none
Rating
6.43 / 8
88 Votes