Created
April 21, 2014 06:02
-
-
Save swimmi/11133595 to your computer and use it in GitHub Desktop.
Is Tom's meadow beautiful now?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <fstream> | |
#include <iostream> | |
#include <algorithm> | |
#include <vector> | |
using namespace std; | |
//Is Tom's meadow beautiful now? | |
int main() | |
{ | |
//ifstream cin("beautiful_meadow.txt"); | |
int n,m; | |
while(cin>>n>>m) | |
{ | |
bool b=true; | |
if(n==0) break; | |
vector<int>v; //mowed squares | |
for(int i=0;i<n;i++) | |
{ | |
for(int j=0;j<m;j++) | |
{ | |
int c; | |
cin>>c; | |
if(c==0) v.push_back(i*10+j); //1<<n,m<<10 | |
} | |
} | |
if(v.size()==0) //no mowed squares | |
b=false; | |
if(v.size()>1) //more than one mowed squares | |
{ | |
vector<int>::iterator it; | |
for(int i=0;i<v.size();i++) | |
{ | |
int a[4]={v[i]-1,v[i]+1,v[i]+10,v[i]-10}; //adjacent squares | |
for(int j=0;j<4;j++) | |
{ | |
it=find(v.begin(),v.end(),a[j]); | |
if(*it>0) //no two squares are adjacent | |
{ | |
b=false; | |
break; | |
} | |
} | |
if(!b) break; | |
} | |
} | |
if(b) cout<<"Yes"<<endl; //beautiful | |
if(!b) cout<<"No"<<endl; //not beautiful | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment