Add new attachment

Only authorized users are allowed to upload new attachments.

This page (revision-4) was last changed on 20-Aug-2015 17:35 by bedzo

This page was created on 20-Aug-2015 17:35 by FREEZX

Only authorized users are allowed to rename pages.

Only authorized users are allowed to delete pages.

Difference between version and

At line 252 added 70 lines
!!Финкимен co breadth first search(bfs):
!C++
%%prettify
{{{
#include <iostream>
#include<queue>
using namespace std;
int mat[51][51],n,m,iii,jjj,miin=99999,mat2[51][51]={0};
bool check(){
for(int i=0;i<n;i++) for(int j=0;j<m;j++) if(mat2[i][j]==0) return false;
return true;
}
void miiin(){
for(int i=0;i<n;i++) for(int j=0;j<m;j++) if(mat[i][j]<miin && mat2[i][j]!=1){
miin=mat[i][j];
iii=i;
jjj=j;
}
}
int main()
{
int i,j,I,J,sum=0,pom;
cin>>n>>m;
queue<int> qi,qj;
for(i=0;i<n;i++) for(j=0;j<m;j++) cin>>mat[i][j];
while(!check()){
miiin();
sum++;
qi.push(iii);
qj.push(jjj);
mat2[iii][jjj]=1;
while(!qi.empty()){
I=qi.front();
J=qj.front();
qi.pop();
qj.pop();
pom=mat[I][J];
if(mat2[I][J+1]==0 && mat[I][J+1]>=pom && J+1<=m){ //desno
qi.push(I);
qj.push(J+1);
mat2[I][J+1]=1;
}
if(mat2[I][J-1]==0 && mat[I][J-1]>=pom && J-1>=0){ // levo
qi.push(I);
qj.push(J-1);
mat2[I][J-1]=1;
}
if(mat2[I+1][J]!=1 && mat[I+1][J]>=pom && I+1<=n){ //dole
qi.push(I+1);
qj.push(J);
mat2[I+1][J]=1;
}
if(mat2[I-1][J]!=1 && mat[I-1][J]>=pom && I-1>=0){//gore
qi.push(I-1);
qj.push(J);
mat2[I-1][J]=1;
}
}
miin=99999;
}
cout<<sum;
return 0;
}
}}}
/%
-- Филип Беџовски
Version Date Modified Size Author Changes ... Change note
4 20-Aug-2015 17:35 6.626 kB bedzo to previous
3 20-Aug-2015 17:35 5.787 kB bedzo to previous | to last
2 20-Aug-2015 17:35 4.378 kB FREEZX to previous | to last
1 20-Aug-2015 17:35 4.354 kB FREEZX to last
« This page (revision-4) was last changed on 20-Aug-2015 17:35 by bedzo