Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- int a[20][20][2];
- void isl(int i, int j, int k, int n, int m) {
- a[i][j][0]=k;
- a[i][j][1]=1;
- if (i>0&&a[i-1][j][0]!=0&&a[i-1][j][1]==0) isl(i-1,j,k,n,m);
- if (i<n-1&&a[i+1][j][0]!=0&&a[i+1][j][1]==0) isl(i+1,j,k,n,m);
- if (j>0&&a[i][j-1][0]!=0&&a[i][j-1][1]==0) isl(i,j-1,k,n,m);
- if (j<m-1&&a[i][j+1][0]!=0&&a[i][j+1][1]==0) isl(i,j+1,k,n,m);
- }
- void show (int n, int m) {
- for (int i=0; i<n;++i)
- {
- for (int j=0;j<m;++j)
- cout<<a[i][j][0];
- cout<<endl;
- }
- }
- int main () {
- int n,m;
- cout<<"Input the scale of the sea(NxM)"<<endl;
- cin>>n>>m;
- for (int i=0;i<n;++i)
- for (int j=0;j<m;++j)
- {
- cin>>a[i][j][0];
- a[i][j][1]=0;
- }
- int is=0;
- for (int i=0;i<n;++i)
- for (int j=0;j<m;++j)
- {
- if (a[i][j][0]!=0&&a[i][j][1]==0) {
- is++;
- isl(i,j,is,n,m);
- }
- }
- show(n,m);
- int* b=new int[is];
- for (int i=0;i<is;++i) b[i]=0;
- for (int i=0;i<n-1;++i)
- for (int j=0;j<m-1;++j) {
- if (a[i][j][0]>0&&a[i+1][j+1][0]>0&&a[i][j+1][0]==0&&a[i+1][j][0]==0&&a[i][j][0]!=a[i+1][j+1][0]) {
- b[a[i][j][0]-1]++;
- b[a[i+1][j+1][0]-1]++;
- }
- if (a[i][j][0]==0&&a[i+1][j+1][0]==0&&a[i][j+1][0]>0&&a[i+1][j][0]>0&&a[i+1][j][0]!=a[i][j+1][0]) {
- b[a[i+1][j][0]-1]++;
- b[a[i][j+1][0]-1]++;
- }
- }
- bool f=1;
- for (int i=0;i<is;++i) if (b[i]==0) {f=0; break;}
- if (is==0) f=0;
- if (is==1) f=1;
- if (f) cout<<"Yes";
- else cout<<"No";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement