CodeForces 948A - Protect Sheep

CodeForces 948A - Protect Sheep

思路

注意:无需最小化狗的数量
转化:每个空地上都放一条狗。遍历矩阵,对所有狼的四周遍历,若有羊输出No否则Yes,每个空地.上都放置一条狗
算法:简单模拟题

代码

include 
using namespace std;
const int N=500+5;
char dp[N][N];
int main(){
    //freopen("datain.txt","r",stdin);
    int n,m;
    cin>>n>>m;
    for (int i=0;icin>>dp[i];
    }
    for (int i=0;ifor (int j=0;jif (dp[i][j]=='W') {
            if (i && dp[i-1][j]=='S'){
                cout<<"No"<return 0;
            }
            if (i1 && dp[i+1][j]=='S'){
                cout<<"No"<return 0;
            }
            if (j && dp[i][j-1]=='S'){
                cout<<"No"<return 0;
            }
            if (j1 && dp[i][j+1]=='S'){
                cout<<"No"<return 0;
            }
        }
    }
    cout<<"Yes"<for (int i=0;ifor (int j=0;jif (dp[i][j]=='.')
                cout<<"D";
            else
                cout<cout<

你可能感兴趣的:(CodeForces 948A - Protect Sheep)