zoj 2850 Beautiful Meadow

//简单题,就是对给出的两个条件进行判断即可!
#include "iostream"
using namespace std;

int meadow[15][15];

int main()
{
	int i, j, N, M;
	bool flag1, flag2;
	while (cin >> N >> M && N && M)
	{
		flag1 = flag2 = false;
		for (i = 0; i < 15; i++)
			for (j = 0; j < 15; j++)
				meadow[i][j] = 2;
		for (i = 0; i < N; i++)
			for (j = 0; j < M; j++)
				cin >> meadow[i][j];
        //第一种情况的搜索!
		for (i = 0; i < N; i++)
		{
			if (flag1)
				break;
			for (j = 0; j < M; j++)
			{
				if (meadow[i][j] != 1)
				{
					flag1 = true;
					break;
				}
			}
		}
		//第二种情况的搜索!
		for (i = 0; i < N; i++)
		{
			if (flag2)
				break;
			for (j = 0; j < M; j++)
			{
				if(meadow[i][j] == 0)
				{
					if (meadow[i][j+1] == 0 || meadow[i+1][j] == 0)
					{
						flag2 = true;
						break;
					}
				}
			}
		}

		
		if (!flag1 || flag2)
			cout << "No" << endl;
		else
			cout << "Yes" << endl;
	}
}

你可能感兴趣的:(zoj 2850 Beautiful Meadow)